Alamofire- acsynchonus. This is why your xmlString is empty. You must wait until you receive a response from Alamofire.
func getXmlString(url: String, completion: (xmlString: String) -> ()) {
var xmlString: String = ""
Alamofire.request(.GET, url)
.validate()
.responseString { response in
xmlString = response.result.value!
completion(xmlString)
}
}
And use it
getXmlString(url: String){ xmlString in
//do something with your String
}
source
share