Make REST API call in Swift

前端 未结 15 1342
被撕碎了的回忆
被撕碎了的回忆 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:38

    edited for swift 2

    let url = NSURL(string: "http://www.test.com")
    
        let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
            print(NSString(data: data!, encoding: NSUTF8StringEncoding))
        }
    
        task.resume()
    

提交回复
热议问题