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

NestedTransformer.TypeOfProperty: Optionals Not Supported #24

Open
cbh2000 opened this issue Jul 27, 2017 · 0 comments
Open

NestedTransformer.TypeOfProperty: Optionals Not Supported #24

cbh2000 opened this issue Jul 27, 2017 · 0 comments

Comments

@cbh2000
Copy link
Contributor

cbh2000 commented Jul 27, 2017

They are actually supported, but it's hard to use and confusing.

I evaluated the code and realized why NestedTransformer's code appears to be stupid. tl;dr, delete the ? from typealias TypeOfProperty = NSNumber?.

    class OptionalAnyToOptionalNSNumberTransformer: NestedTransformer {
            typealias TypeOfData = Any?
            typealias TypeOfProperty = NSNumber? // Should be NSNumber, but most people will put in an optional.
            
            func setter(_ dataValue: Any?, type: Any.Type) throws -> NSNumber {
                if let number = dataValue as? NSNumber {
                    return number
                } else if let string = dataValue as? String, let integer = Int(string) {
                    return NSNumber(integerLiteral: integer)
                } else {
                    throw OptionalAnyToOptionalNSNumberTransformerError.unrecognizedNumber(given: dataValue)
                }
            }
            
            func getter(_ propertyValue: NSNumber) throws -> Any? {
                return propertyValue
            }
        }
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