2016-01-20 99 views
0

我收到以下錯誤消息。我的XCode版本7.1,Swift AFNetworking POST錯誤

/Users/chamath/Desktop/SwiftNvoi/Mobile/Mobile/APISFAuthentication.swift:30: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

謝謝jervine10 –

+0

如何將responseObject存儲在NSData或NSArray中? – bhadresh