Hi dev community,
I am currently test-driving swift2 on a logging library. Good topic to start with, as it can start simple, and end up much more complex.
I am having problems with the init of my objects : I want to be able to create them from a dictionary. But this requires a lot of validation, as dictionaries may be missing some mandatory values, or contain object of a wrong type.
Swift provides a way to declare failable init method, by declaring them with a "?". Nice, but returning nil will not be very informative.
So to provide feedback, I would like to use the error handling model of swift 2, and throw error from the init with some details about what is wrong with the configuration dictionary.
In some cases, it works. But many of my unit tests are crashing, with SIGABRT, and a message in the console : "pointer being freed was not allocated".
Is it a valid construct to use throw in a init ?
If not, I suppose I will have to create an empty object and then update it with the content of the dictionary in another method that can throw.
The project's sources can be found here : https://github.com/jduquennoy/Log4swift.