Handling XML data with Alamofire in Swift

后端 未结 7 1974
一向
一向 2020-12-24 02:57

I started to use cocoapods with my current ios project. I need to use SOAP to get content with easy way for my ios project. I have googled it and Alamofire pod is great for

7条回答
  •  攒了一身酷
    2020-12-24 03:09

    Using Alamofire 3.0 current version as of Sept 2015 and Xcode 7.

    The implementation bellow has the advantage of not using an additional external library such as SWXMLHash

    Alamofire.request(.GET, urlString, encoding: .PropertyList(.XMLFormat_v1_0, 0)).responsePropertyList { request, response, result in
    
    //Note that result have two properties: error and value as of Alamofire 3.0, check the migration guide for more info
    
      if let error = result.error {
        print("Error: \(error)")
    
        // parsing the data to an array 
      } else if let array = result.value as? [[String: String]] {
    
        if array.isEmpty {
          print("No data")
    
        } else { 
          //Do whatever you want to do with the array here
        }
      }
    }
    

提交回复
热议问题