Search code examples
soapswift2alamofire

Is it possible to use Soap API using Almofire in Swift 2.2


I am using both Rest & Soap API in my iOS application .For Rest API I can easily use Alamofire for both POST & GET method .But in Case of SOAP ,I am not able to handle the XML response .


Solution

  • Parse SOAP API using Alamofire and SWXMLHash Libraries easy to use for parsing : -

    Swift 2.2

    //MARK:- Parsing API here
     func parseMyApi(is_URL: String, completion: (result: String) -> Void) {
    
       Alamofire.request(.GET, is_URL)
                .responseJSON { response in
                        let xmls = SWXMLHash.parse(response.data!)
                        func enumerate(indexer: XMLIndexer, level: Int) {
                            for child in indexer.children {
                                let name:String? = child.element!.name
                                print("\(level) \(name)")
                                // Take Link from XML data here 
                                if name! == "link" {
                                    let text = child.element!.text
                                    if text?.isEmpty == false{
                                       print(text)
                                      // Finish here Process
                                      completion(result: text!)
                                    }
                                }
                                enumerate(child, level: level + 1)
                            }
                        }
                    enumerate(xmls, level: 0)
                }
           }
    }
    

    And you can see this example also for Soap parsing.