In Objective-C we can use object mapping with json response like this way
PolicyData *policyData = [[PolicyData alloc] initWithDictionary:responseObject error:&err];
Here we can map responseObject with PolicyData class properties. How i can do the same in Swift?
It should be as easy as adding a bridging header (because
PolicyData
is likely written in Objective-C). Instructions on how to do this can be seen in this Apple documentation.Then you can create that
PolicyData
object as easily as doing:This assumes your
responseObject
is a NSDictionary. And Swift 2 helpfully (?) turns error parameters into try/catch blocks.That is, PolicyData's
declaration magically becomes
as described in the "Error Handling" section of this Apple Objective-C/Swift interoperability doc.