Hello I am using Object Mapper with Alamofire in Swift and I am trying to map enum raw value to real Enum.
Here is my enum and also the code I am trying to use in function mapping. Can you please help me what to pass as argument to EnumTransform or how to modify the code? I know I can read the value as string and the use LevelType(rawValue: stringValue).
Thanks in advance.
enum LevelType : String { case NEW = "NEW" case UPDATE = "UPDATE" } func mapping(map: Map) { typeEnum <- (map[“type”], EnumTransformable(???) ) }
You don't have to pass an argument at all. All you have to do is to specify enum type as generic argument and ObjectMapper will take care for all enum initialization procedures.
typeEnum <- (map["type"],EnumTransform<LevelType>())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With