【问题标题】:NSXMLParser didStartElement getting attributeDict issueNSXMLParser didStartElement 获取 attributeDict 问题
【发布时间】:2015-01-16 10:02:15
【问题描述】:

我正在尝试获取 NSXMLParser didStartElement 中的属性字典。我的问题是我在调用attributeDict 时出错(找不到接受提供的参数的“下标”的重载)。我调用的方法对吗?我想调用所有符号键,然后将其添加到数组中。

    func parser(parser: NSXMLParser!, didStartElement elementName: String!, namespaceURI: String!, qualifiedName qName: String!, attributes attributeDict: [NSObject : AnyObject]!)
{
    element = elementName

    if (elementName as NSString).isEqualToString("p")
    {
        println("Element's attributes are \(attributeDict)")
        //Result
        //Element's attributes are [bid: 1.16301, offer: 1.16321, symbol: EUR/USD]


        elements = NSMutableDictionary.alloc()
        elements = [:]
        title1 = NSMutableString.alloc()
        title1 = ""

        title1 = String(attributeDict["symbol"]) //Error
    }
}

【问题讨论】:

  • 首先检查你是否得到了可变字典??而不是在该字典中找到键“符号”。比定义 title1 = attributeDict["symbol"]!作为 NSMutableString

标签: ios swift nsxmlparser


【解决方案1】:

我希望这能解决您的问题

title1 = attributeDict["symbol"]! as NSMutableString

【讨论】:

    猜你喜欢
    • 2014-03-11
    • 2012-02-18
    • 1970-01-01
    • 2012-01-05
    • 1970-01-01
    • 2016-05-13
    相关资源
    最近更新 更多