You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!
The text was updated successfully, but these errors were encountered:
balazsgerlei
changed the title
Automatically parse 0 and 1 to Bool
Automatically parse 0 or 1 to Bool
Nov 6, 2016
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:
Swift 3.x (Somehow casting to Int always results in nil):
Thanks in advance!
The text was updated successfully, but these errors were encountered: