IOS Swift 3 Alamofire 4.0.0

时间:2016-10-03 11:26:28

标签: ios swift3 alamofire

这是我的代码在NSMutable行遇到错误:

import UIKit
import Alamofire

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let url = NSURL(string: "http://jsonplaceholder.typicode.com/users")
        var request = NSMutableURLRequest(URL:url!)
        request.HTTTPMethod = "GET"
        request.setValue("application/json",forHTTTPHeaderField:"Content-Type")
        Alamofire.request(request).responseJSON{
            response in
            switch resposnse.result{
            case.Success(let data):
                print("Successfully grabbed response",data)
            case.Failure(let error):
                print("request failed with error\(error)")
            }
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

请有人解决我的问题吗?

2 个答案:

答案 0 :(得分:2)

尝试使用以下代码进行Alamofire 4.0

umask

答案 1 :(得分:1)

试试这个

Alamofire.request( url, method: .get , parameters: nil, encoding:  JSONEncoding.default).responseJSON{
            response in
            if response.result.isSuccess {
                //some code
            }
        }