Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling an attribute of an XML element in Swift

I want to read the url attribute from this element by using NSXMLParser:

<enclosure url="http://www.marketoloji.com/wp-content/uploads/2015/01/IMG_1649-110x110.jpg" length="7113" type="image/jpg"/>

I found this resource on Apple site but it's for obj C, not for Swift:

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/XMLParsing/Articles/HandlingElements.html#//apple_ref/doc/uid/20002265-BCIJFGJI

I know that I should work with attributeDict dictionary in didStartElement method but dont know how.

like image 678
johncoffey Avatar asked Feb 08 '15 18:02

johncoffey


1 Answers

I learned it and here is the way it works in Swift:

in didStartElement method;

if element.isEqualToString("enclosure") {
        var imgLink = attributeDict["url"] as String
    }
like image 123
johncoffey Avatar answered Nov 15 '22 07:11

johncoffey