Alamofire Contextual type anyobject不能与字典文字

时间:2016-08-14 21:51:41

标签: swift rest alamofire nsurl

我正在调用POST请求,我从另一个方法提供params,url并得到错误:

Contextual type anyobject cannot be used with dictionary literal

这是我在此处调用并获取错误的方法:

API.sharedInstance.post(NSURL(string: baseURL)!, params: ["name":  val, "owner": "John"])

这是我的Alamofire代码:

func post(url: NSURL, params: AnyObject) {

    Alamofire.request(.POST, baseURL, parameters: params as! [String : AnyObject])
        .validate()
        .responseJSON { response in
            switch response.result {
            case .Success:
                print("Validation Successful")
                print("response = \(response)")
            case .Failure(let error):
                print(error)
            }
    }

}

1 个答案:

答案 0 :(得分:0)

尝试替换

func post(url: NSURL, params: AnyObject) {    
    Alamofire.request(.POST, baseURL, parameters: params as! [String : AnyObject])

func post(url: NSURL, params: [String : AnyObject]) {    
    Alamofire.request(.POST, baseURL, parameters: params)