通過在CocoaPods中篩選之後,發這個這個比較好用,整理出來git
若是有須要能夠在Pods命令端輸入:github
pod search xml
這樣會搜索出不少相關Xml的第三方庫swift
SwiftyXMLParser是在Swift下的一個xml解析第三方庫,支持索引,支持keyValue形式訪問,app
環境和語言支持:iOS 8.0+ , Swift 2.0+url
使用:spa
let urlStr = ApiUrl + "/" + xmlFile(newsType) Alamofire.request(.GET, urlStr).responseData { (response) in let xml = XML.parse(response.result.value!) let channel = xml["rss"]["channel"] let items = channel["item"] var array:[XPNews] = [] for item in items { let model:XPNews = XPNews() model.newsTitle = item["title"].text model.newsLink = item["link"].text model.newsDesc = item["description"].text model.newsTime = item["pubdate"].text?.toDateWith("yyyy-MM-dd HH:mm:ss") model.newsTypeStr = item["category"].text model.newsThumb = item["enclosure"].attributes["url"]! array.append(model) } if (finishedHandler != nil) { finishedHandler!(msg: "獲取成功",responseObject: array) } }
其餘更多使用詳情參見GitHub xml
GitHub地址:https://github.com/yahoojapan/SwiftyXMLParserblog