I need to interrogate our Api to populate our main screen, so I set up a separate class called RestApiManager
and added the code below:
import UIKit
class RestApiManager: NSObject {
static let sharedInstance = RestApiManager()
let baseURL = "http://api.randomuser.me/"
func getData() {
let request = NSMutableURLRequest(URL: NSURL(string: baseURL)!)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
if data != nil {
do {
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableLeaves) as? NSDictionary //:JSON = JSON(data: jsonData)
}catch _ as NSError
{
}
}
})
task.resume()
}
}
I used the url shown as a simple test, as I know it returns data without any properties as i tested it in my browser but each time I run my app the data is always nil.
What am I doing wrong?