I have a separate class for all my json api requests calls: userJson.swift
I want to have functions in here that return the json so I can work with the json in my controllers. This is one of my functions in it:
func signIn(email: String, username: String, password: String){
var request : NSMutableURLRequest = NSMutableURLRequest()
request.URL = NSURL(string: signUpURL)
request.HTTPMethod = "POST"
let body = "email=\(email)&username=\(username)&password=\(password)"
request.HTTPBody = body.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request)
{
data, response, error in
if (error != nil) {
return error
} else {
let json = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
return json
}
}
task.resume()
}
I want to return json but it gives me an error: 'NSDictionary' is not convertible to 'Void'. How can I just return the json so I can work with it in my controller?