Make REST API call in Swift

前端 未结 15 1381
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 04:20

I\'m trying to use Swift to make a GET call to a REST API, and have tried to follow numerous tutorials, but can\'t figure it out. Either because I cannot figure out how to

15条回答
  •  青春惊慌失措
    2020-12-02 04:55

    I think the NSURLSession api fits better in this situation. Because if you write swift code your project target is at least iOS 7 and iOS 7 supports NSURLSession api. Anyway here is the code

    let url = "YOUR_URL"
    
    NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: url)) { data, response, error in
        // Handle result
    }.resume()
    

提交回复
热议问题