I want to use an api for a swift app and I need to make a URL request to retrieve information in a json format.
I tried to follow an online example:
var urlString = "http://api.shephertz.com" // Your Normal URL String
var url = NSURL.URLWithString(urlString)// Creating URL
var request = NSURLRequest(URL: url) // Creating Http Request
var response:AutoreleasingUnsafePointer<NSURLResponse?> = nil;
var error: AutoreleasingUnsafePointer<NSErrorPointer?> = nil;
// Sending Synchronous request using NSURLConnection
var responseData = NSURLConnection.sendSynchronousRequest(request, returningResponse: response, error:nil) as NSData
if error != nil
{
// You can handle error response here
}
else
{
//Converting data to String
var responseStr:NSString = NSString(data:responseData, encoding:NSUTF8StringEncoding)
}
But I haven't ever seen the AutoreleasingUnsafePointer used and I can't find anything about it in the Apple's documentation. The above example did not work and I was wondering if there was any other way to do it.