-
Notifications
You must be signed in to change notification settings - Fork 58
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
Dealing with optional variables (basic types and enum) #81
Comments
@jimmyti there's a lot here, so let me know if I miss something.
try date <~> map["date"]
.transformFromNode(stringToOptionalDate)
.transformToNode(optionalDateToString)
Let me know if you see other things! |
@loganwright thank you for answering!
enum FooType: Int8 {
case typeA
case typeB
}
class Bar: BasicMappable {
var foo: FooType?
var date: Date?
var name: String?
var foos: [FooType]?
required init() {
}
func sequence(map: Map) throws {
try foo <~> map["foo"]
.transformFromNode {
FooType(rawValue: $0)
}
.transformToNode {
$0!.rawValue
}
try date <~> map["date"]
try foos <~> map["foos"]
.transformFromNode {
// how to handle transforming node to enum collection
}
.transformToNode {
// how to handle transforming enum collection to JSON
}
}
} |
@jimmyti let me look into the optional thing, you should be able to, but the transform functions are super generic, and sometimes require more type information in unexpected ways. For this stuff though, I think you'd reduce a lot of your code by conforming func sequence(map: Map) throws {
try foo <~> map["foo"]
try date <~> map["date"]
try foos <~> map["foos"]
} |
I am learning how to use Genome, and so far I am impressed with the flexibility offered by Genome. 👍
Example class definition:
The text was updated successfully, but these errors were encountered: