Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically parse 0 or 1 to Bool #60

Open
balazsgerlei opened this issue Nov 6, 2016 · 1 comment
Open

Automatically parse 0 or 1 to Bool #60

balazsgerlei opened this issue Nov 6, 2016 · 1 comment

Comments

@balazsgerlei
Copy link

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!

@balazsgerlei balazsgerlei changed the title Automatically parse 0 and 1 to Bool Automatically parse 0 or 1 to Bool Nov 6, 2016
@balazsgerlei
Copy link
Author

Any thoughts on this @aryaxt ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant