3
我想獲取NSXMLParser didStartElement中的attributeDict。我的問題是我在調用attributeDict時發生錯誤(無法找到接受提供參數的'subscript'的重載)。我是否稱這個方法正確?我想調用所有的符號鍵,然後將它添加到數組中。NSXMLParser didStartElement獲取屬性代碼問題
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 –