2016-01-20 5 views
0

Я получаю следующее сообщение об ошибке. Мой XCode версии 7.1,Swift AFNetworking POST error

/Users/chamath/Desktop/SwiftNvoi/Mobile/Mobile/APISFAuthentication.swift30:22: Невозможно преобразовать значение типа '(AFHTTPRequestOperation !, NSError!) ->()' в ожидаемое тип аргумента '((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

ответ

2

Вам не нужно указывать тип класса при заполнении параметров в блоке. Обновите параметры следующим образом:

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) 
     }) 

    } 
+0

Thanks jervine10 –

+0

Как сохранить responseObject в NSData или NSArray? – bhadresh

Смежные вопросы