Chamath Jeevan
Chamath Jeevan

Reputation: 5172

Swift AFNetworking POST error

I am getting the following error. My XCode version 7.1 ,

/Users/chamath/Desktop/SwiftNvoi/Mobile/Mobile/APISFAuthentication.swift:30:22: Cannot convert value of type '(AFHTTPRequestOperation!, NSError!) -> ()' to expected argument type '((AFHTTPRequestOperation?, NSError) -> Void)?'

import Foundation

class APISFAuthentication {


    init(x: Float, y: Float) {

    }



    func fAuthenticateUser(userEmail: String) -> String {

          let manager = AFHTTPRequestOperationManager()
        let postData = ["grant_type":"password","client_id":APISessionInfo.SF_CLIENT_ID,"client_secret":APISessionInfo.SF_CLIENT_SECRET,"username":APISessionInfo.SF_GUEST_USER,"password":APISessionInfo.SF_GUEST_USER_PASSWORD]

        manager.POST(APISessionInfo.SF_APP_URL,
            parameters: postData,
            success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!) in
                print("JSON: " + responseObject.description)
            },
            failure: { (operation: AFHTTPRequestOperation!,error: NSError!) in
                print("Error: " + error.localizedDescription)
        })

    }
}

enter image description here

Upvotes: 0

Views: 1333

Answers (1)

jervine10
jervine10

Reputation: 3077

You don't need to specify the class type when filling in the parameters in a block. Update the parameters like this:

func fAuthenticateUser(userEmail: String) -> String {

          let manager = AFHTTPRequestOperationManager()
        let postData = ["grant_type":"password","client_id":APISessionInfo.SF_CLIENT_ID,"client_secret":APISessionInfo.SF_CLIENT_SECRET,"username":APISessionInfo.SF_GUEST_USER,"password":APISessionInfo.SF_GUEST_USER_PASSWORD]

        manager.POST(APISessionInfo.SF_APP_URL,
            parameters: postData,
            success: { (operation, responseObject) in
                print("JSON: " + responseObject.description)
            },
            failure: { (operation, error) in
                print("Error: " + error.localizedDescription)
        })

    }

Upvotes: 2

Related Questions