【问题标题】:Swift AFNetworking POST errorSwift AFNetworking POST 错误
【发布时间】:2016-01-20 17:13:41
【问题描述】:

我收到以下错误。我的 XCode 7.1 版,

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

    }
}

【问题讨论】:

    标签: ios xcode swift swift2 afnetworking-2


    【解决方案1】:

    在块中填写参数时不需要指定类类型。像这样更新参数:

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

    【讨论】:

    • 如何将responseObject存储在NSData或NSArray中?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    • 1970-01-01
    相关资源
    最近更新 更多