I am trying to implement an NSXMLParserDelegate in Swift but I am having issues using the attributes dictionary in some of the delegate methods. For instance, in parser:didStartElement:
:
func parser(parser: NSXMLParser!, didStartElement elementName: String!, namespaceURI: String!, qualifiedName qName: String!, attributes attributeDict: [NSObject : AnyObject]!) {
trying to access attributeDict values like:
if self.feedType == FeedType.RSS {
self.insideLink = true
} else {
if (String(attributeDict["rel"]) == "alternate") && (String(attributeDict["type"]) == "text/html") {
self.link = String(attributeDict["href"])
self.insideLink = false
self.doneWithLink = true
}
}
I get an error message: "'String' is not convertible to 'FeedType'".
enum FeedType:String {
case ATOM = "feed"
case RSS = "rss"
}
class FeedParser:NSObject, NSXMLParserDelegate {
var feedType:FeedType?
Is an error. Same for a dozen other variations on the theme... any insights?
I guess the question is how to properly use the key / value pairs in attributeDict
which are of type [NSObject: AnyObject]
?