SwiftyJSON Alamofire 无法使用类型为 ((_,_,_,_))->_) 的参数列表调用 responseJSON

Posted

技术标签:

【中文标题】SwiftyJSON Alamofire 无法使用类型为 ((_,_,_,_))->_) 的参数列表调用 responseJSON【英文标题】:SwiftyJSON Alamofire Cannot invoke responseJSON with an argument list of type ((_,_,_,_))->_) 【发布时间】:2015-05-30 23:21:10 【问题描述】:

以下代码在使用 SwiftyJSON 和 Alamofire 时经常出现问题:

extension Bool 
func toString() -> String? 
    switch self 
    case true:
        return "true"
    case false:
        return "false"
    default:
        return nil
    


                var _enabled: Bool?
                var _username: String?
                var _email: String?

                // Bit where we set the username, enabled and email

                let _baseUrl = "https://url.com/path"

                var createUserJSON = ["user": ["username": _username!, "email": _email!, "enabled": _enabled!.toString()]]

                request(.POST, _baseUrl + "/users", parameters: createUserJSON, encoding: .JSON)
                    .responseJSON  (request, response, data, error) in
                        // Blah blah do stuff
                

由于某种原因,我收到错误 Cannot invoke responseJSON with a argument list of type ((,,,))->_)

这似乎经常发生,我通常只是在反复试验和一点运气后修复它。我在 *** 上找不到任何帮助

谁能帮忙?

【问题讨论】:

【参考方案1】:

想通了,bool.toString() 函数需要用 ! 强制解包

【讨论】:

以上是关于SwiftyJSON Alamofire 无法使用类型为 ((_,_,_,_))->_) 的参数列表调用 responseJSON的主要内容,如果未能解决你的问题,请参考以下文章