The init method is necessary so that ObjectMapper can create an instance of the object it is trying to map. It also allows you to do some validation before mapping. If a certain key that you need doesn't exist you can return nil from init?(_ map: Map) and the mapping will not happen.
This should definitely be noted in the documentation (README.md)!
Out of interest why is there an init and a mapping function? Can the failable initialiser not be used for both purposes?
@eoinoconnell The mapping could technically occur within the init function, but if we took that approach we would lose the ability write JSON and to map JSON to an existing object.
OK cool, valid point. Thanks!
The readme has now been updated with the information above
Most helpful comment
This should definitely be noted in the documentation (
README.md)!