Leonardo Leonardo - 1 year ago 81
Swift Question

Xcode, big array of NsDictionary consume all my RAM

i have a problem with my new app. I have to get and parse a big xml from a WebService, using XmlToDictionary to make all easier.
When i try to build my app, if i look in the task manager, the is a task ("SourceKit") which consumes all my RAM.
Searching on internet i think that i understood the problem : The result of my parsing is a big array of NSDictionary with "not explicitly" type.

So my question is : do you know another way to manage this array of NSDictionary ? Or a method for explicitly declare this array? or any another way?
This is my code :

//The block of the HTTP connection for get the xml form the WebService.
operation.setCompletionBlockWithSuccess({ (operation, response) -> Void in

parser = response as? XMLParser
let XmlPars = XmlParsing()
XmlPars.parsing(parser: parser!)

}, failure: { (operation, error) -> Void in

func parsing (parser : XmlParser){
let xmlStruttureTipi = (dictionary["StruttureTipi"] as! NSDictionary)
let struttureTipi = (xmlStruttureTipi[xmlStruttureTipi.allKeys[0]] as! Array<NSDictionary>)
parseStruttureTipi(struttureTipi: struttureTipi)

func parseStrutture {

func parseStrutture(strutture : [NSDictionary]) {

let formatter = DateFormatter()
var ArrayStrutture = [Struttura]()
for struttura in strutture{
let s = Struttura()

formatter.dateFormat = "dd-MM-yyyy"
let data = formatter.date(from: struttura["DataAggiornamento"] as! String)!

if(struttura["DataAggiornamento"] != nil){s.DataAggiornamento = data}else{s.DataAggiornamento = formatter.date(from: "00-00-0000")}

if(struttura["Longitudine"] != nil){s.Longitudine = Double((struttura["Longitudine"] as? String)!)}else{s.Longitudine = 0.0}

if(struttura["Latitudine"] != nil){s.Latitudine = Double((struttura["Latitudine"] as? String)!)}else{s.Latitudine = 0.0}

if(struttura["Nome"] != nil)
{s.Nome = struttura["Nome"] as? String}
else{s.Nome = ""}

//A lot other proprety...


let repoStrutture = RepoStruture()
repoStrutture.insertStrutture(strutture: ArrayStrutture)



Answer Source

I solved the problem by myself, the problem was the declaration od the NSDictionary : if i split it in two NSDictionary it works. I think it's a bug of the compiler.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download