I'm getting the error "extra argument in call" from my httpGet(request) and I'm not sure why. I've looked at several stack exchange solutions and it seems like I'm doing everything that the solutions are suggesting. Extra argument 'error' in call. Compilation error in Swift 2.0. With this solution in particular- it looks like I am doing the error handling correctly.
class func userNameCall() -> String {
let request = NSMutableURLRequest(URL: NSURL(string: "my url goes here")!)
httpGet(request) { string, error in
guard error == nil && string != nil else {
print(error?.localizedDescription)
return
}
let data = string!.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
do {
let json = try NSJSONSerialization.JSONObjectWithData(data, options: []) as! [String: AnyObject]
//if JSON returns error with key "msg" meaning log in was not successful
if let message = json["msg"] as! String?{
if (message == "Invalid login."){
self.signInFailedAlert()
return "Invalid login"
}
}
//if JSON has key "value", meaning a session ID was created and login was successful, continue to second call
if let sessionID = json["value"] as! String?{
print("sessionID from httpCall class: " + sessionID)
return sessionID
}
} catch let error as NSError { //
print("Failed to load: \(error.localizedDescription)")
}
}
}
func httpGet(request: NSURLRequest, callback: (String?, NSError?) -> Void) {
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in
guard error == nil && data != nil else {
callback(nil, error)
return
}
callback(String(data: data!, encoding: NSUTF8StringEncoding), nil)
}
task.resume()
}
Can anyone tell me what I'm doing wrong? Thank you!