Search code examples
iosswiftnsxmlparser

NSXMLParser didStartElement getting attributeDict issue


I'm trying to get the attributeDict in the NSXMLParser didStartElement. My issue is I'm getting an error in calling the attributeDict (Could not find an overload for 'subscript' that accepts the supplied arguments). Am I calling the method right? I want to call all symbol keys and then add it to an array.

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

Solution

  • i hope this fix your issue

    title1 = attributeDict["symbol"]! as NSMutableString