0

I am new to swift/ios/alamofire.

Wondering if there is a elegant/intuitive way of decoding a json string (or dictionary) to a swift object.

I am using Alamofire 3.0 and have been manually subscripting dictionary keys and passing them to my class's constructor to initialize it in responseJSON callback method of Alamofire's request method.

Any help on pointing me towards more elegant solution will be appreciated.

user462455
  • 12,838
  • 18
  • 65
  • 96
  • Have you ever tried JSONModel? Find it at https://github.com/icanzilb/JSONModel. Use bridging headers to use this library along with Swift. Here is a good tutorial on using Objective-C library in Swift. http://stackoverflow.com/questions/24002369/how-to-call-objective-c-code-from-swift – Sauvik Dolui Nov 12 '15 at 06:47

1 Answers1

0

Try this:

let parameters = [
        "username": username.text!,
        "password": password.text!,
]

Alamofire.request(.POST, "your_url_here", parameters: parameters)
            .responseJSON { request, response, result in
    print(result)
}
Orkhan Alizade
  • 7,379
  • 14
  • 40
  • 79