Happiehappie Happiehappie - 1 year ago 98
Swift Question

Alamofire and SwiftyJSON for Swift 2.0

I am updating my code for Swift 2.0 for today, however the line

var json = JSON(json)
gives me the following error

Cannot invoke intializer for type 'JSON' with an argument list of type

Do you guys have any idea how should I change my code?

@IBAction func changePassword(sender: UIBarButtonItem) {
Alamofire.request(.POST, AppDelegate.kbaseUrl + "users/me/password", parameters: ["old_password": self.oldPasswordTextField.text!, "new_password": self.newPasswordTextField.text!, "confirm_password": self.confirmPasswordTextField.text!], encoding: .JSON)
.responseJSON {
(req, res, json) in
var json = JSON(json)
if json["meta"]["status"]["code"] == 200 {
let alert = UIAlertView(title: json["meta"]["msg"]["subj"].stringValue, message: json["meta"]["msg"]["body"].stringValue, delegate: nil, cancelButtonTitle: "Close")

Answer Source

Now the response object came with it so you have to use the value property from the response object

So it will be JSON(json.value!)

For example :

Alamofire.request(.GET, "http://api.androidhive.info/contacts/", parameters: nil, encoding: .JSON, headers: nil).responseJSON { (req, res, json) -> Void in
    print("JSON - \(json.value)")

    let swiftJsonVar = JSON(json.value!)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download