Skip to content

Instantly share code, notes, and snippets.

@TonSDe
Last active October 23, 2019 04:45
Show Gist options
  • Save TonSDe/9414cb38489c3d3004df29dca1a21319 to your computer and use it in GitHub Desktop.
Save TonSDe/9414cb38489c3d3004df29dca1a21319 to your computer and use it in GitHub Desktop.
DispatchQueue
// ตัวอย่างการทำงานของ Task
var ID:string = nil
func getDataFromURL() {
let URL:string = "https://xxx...."
Alamofire.request(URL, method: .get, parameters: nil).responseJSON { response in
let dataJSON = JSON(response.result.value!)
if let id:String = dataJSON["data"]["id"].string {
self.ID = id
}
}
self.checkData()
}
func checkData() {
if self.ID == nil {
print("ID = Nil")
} else {
print("ID != Nil")
}
}
// Run Function
self.getDataFromURL() //OUTPUT = ID = Nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment