NSXMLParser didStartElement获取attributeDict问题

时间:2015-01-16 10:02:15

标签: ios swift nsxmlparser

我正在尝试在NSXMLParser didStartElement中获取attributeDict。我的问题是我在调用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
    }
}

1 个答案:

答案 0 :(得分:2)

我希望这可以解决您的问题

title1 = attributeDict["symbol"]! as NSMutableString