Skip to content

Instantly share code, notes, and snippets.

@mazz
Created May 21, 2017 03:35
Show Gist options
  • Save mazz/86abd089b2f7a1c7a01f4669126eb988 to your computer and use it in GitHub Desktop.
Save mazz/86abd089b2f7a1c7a01f4669126eb988 to your computer and use it in GitHub Desktop.
let session = URLSession.shared
let task = session.dataTask(with: request as URLRequest, completionHandler: {(data, response, error) in
if (error == nil) {
do {
let json = try! JSONSerialization.jsonObject(with: data!, options: [])
let books = Mapper<BookResponse>.mapArray(json) // ERROR: Argument labels '(_:)' do not match any available overloads
if let jsonResult = try JSONSerialization.jsonObject(with: data!, options: []) as? NSDictionary {
print(jsonResult)
DispatchQueue.main.async {
success(jsonResult)}
}
}
}
});
task.resume()
@mazz
Copy link
Author

mazz commented May 21, 2017

BookResponse.swift:


import Foundation
import ObjectMapper

class BookResponse : Mappable {
    var books : [Book]?
    
    /// This function can be used to validate JSON prior to mapping. Return nil to cancel mapping at this point
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        books  <- map["result"]
    }
    
}

@hammadzz
Copy link

let books = Mapper<BookResponse>().mapArray(json)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment