Nurdin
Nurdin

Reputation: 23893

Swift - Cannot invoke initializer for type 'JSON' with an argument list of type '(Response<AnyObject, NSError>)'

I got this error message after upgrade with Xcode 6.2 to Xcode 7.0.1.

/Users/ZERO/Documents/Xcode/XXXXX/Controllers/LoginViewController.swift:75:35: Cannot invoke initializer for type 'JSON' with an argument list of type '(Response)'

My code.

Alamofire.request(.POST , "http://192.168.1.124/wsesb.asmx/WSIniLogin", parameters: ["device_id": UIDevice.currentDevice().identifierForVendor!.UUIDString,"acc_token":acc_token])
            .responseJSON { response in
                if response.result.isSuccess {
                    var jsonObj = JSON(response) //error here
                        if(jsonObj[0]["Status"] == "SUCCESS"){//error here
                            if(jsonObj[0]["Data"][0]["Status"] == "SUCCESS"){ //error here

                            }
                         }
                }
        }

My podfile settting:

pod 'Alamofire', '~> 3.0'
pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git'

Upvotes: 0

Views: 2016

Answers (1)

Alexey Pichukov
Alexey Pichukov

Reputation: 3405

response is a Struct of Response type. If you need get JSON from it, do something like this:

if response.result.isSuccess {
    var jsonObj = JSON(response.result.value)
    ...
}

Upvotes: 1

Related Questions