Handling an attribute of an XML element in Swift

I want to read the url attribute of this element 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 the Apple website, but it is for obj C, not Swift:

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

I know that I have to work with the attributeDict dictionary in didStartElement , but I don’t know how to do it.

+5
source share
1 answer

I found out about this, and here is how it works in Swift:

in the didStartElement method;

 if element.isEqualToString("enclosure") { var imgLink = attributeDict["url"] as String } 
+7
source

Source: https://habr.com/ru/post/1212912/


All Articles