OCMapper
OCMapper copied to clipboard
Automatically parse 0 or 1 to Bool
It is quite common for a server to return 0 or 1 for boolean values. It would be great if OCMapper could automatically parse this as booleans. I use it in Swift but I think this is possible to implement both in Swift and Objective-C.
For now, I created a MappingTransformer for this which I have to set for every parameter where I would like to use it:
Swift 2.x:
let intToBoolTransformer: MappingTransformer = {
currentNode, parentNode in
return currentNode as? NSNumber == 1 ? true : false
}
Swift 3.x (Somehow casting to Int always results in nil):
let intToBoolTransformer: MappingTransformer = {
currentNode, parentNode in
return currentNode as? NSNumber == 1 ? true : false
}
Thanks in advance!
Any thoughts on this @aryaxt ?