I want to link my backend python with my front end ios swift app. I want to call for a get api call. I tried all the answers on stack overflow: like this one:
var url : String = "http://google.com?test=toto&test2=titi"
var request : NSMutableURLRequest = NSMutableURLRequest()
request.URL = NSURL(string: url)
request.HTTPMethod = "GET"
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler:{ (response:NSURLResponse!, data: NSData!, error: NSError!) -> Void in
var error: AutoreleasingUnsafeMutablePointer<NSError?> = nil
let jsonResult: NSDictionary! = NSJSONSerialization.JSONObjectWithData(data, options:NSJSONReadingOptions.MutableContainers, error: error) as? NSDictionary
if (jsonResult != nil) {
// process jsonResult
} else {
// couldn't load JSON, look at error
}
but it gave me an error on line 3 saying consecutive declarations on a line must be separated by ;
Also, I tried the following: override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor(red: 255/255.0,green:200/255.0,blue:100/255.0,alpha:1)
let url = URL(string:"http://127.0.0.1:5000/")!
let urlRequest = URLRequest(url: url)
let session = URLSession.shared
let task = session.dataTask(with: urlRequest, completionHandler: { (data, response, error) in
guard error == nil else {
print("error calling GET on /todos/1")
print(error!)
return
}// do stuff with response, data & error here
})
guard let responseData = data else{
print("Error: did not receive data")
return
}
but data in line 11 was not identified