0

我的新应用有问题。我必须从 WebService 获取并解析一个大 xml,使用XmlToDictionary使一切变得更容易。当我尝试构建我的应用程序时,如果我查看任务管理器,这是一个消耗我所有 RAM 的任务(“SourceKit”)。在互联网上搜索我认为我理解了这个问题:我的解析结果是一大堆具有“未明确”类型的NSDictionary 。

所以我的问题是:你知道管理这个 NSDictionary 数组的另一种方法吗?或者显式声明这个数组的方法?或任何其他方式?这是我的代码:

 //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
                print(error.localizedDescription)
        })
        operation.start()

    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...

            ArrayStrutture.append(s)
        }

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

    }

}
4

1 回答 1

0

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.

于 2016-10-26T07:17:20.127 回答