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
ResponseObjectSerializable's creation method should return a (T?, NSError?) tuple #230
Comments
At the time of writing, Swift did not yet have failable initializers, which is definitely something that would be desirable when interacting with unknown and potentially untrusted data from an external web service. b5d6f58 makes this change to add such a consideration. |
…podspec * 'master' of https://github.com/Alamofire/Alamofire: [Issue Alamofire#230] Making response object example initializer failable Fixing optional textLabel property on cells Adding missing forced unwrap in test [Issue Alamofire#226] Fixing optional cookie entry in cURL output Fixing possible exception when force unwrapping optional header properties
The code after your change @mattt does not compile: But even then your example is not there yet, because if there is a missing value it will still just crash instead of failing and returning nil with the message: What would be the best way of going about it? |
I have mixed feelings about failable initializers, but I also deal a lot with missing or invalid data in my json responses. The example you give of an object that implements ResponseObjectSerializable will crash if the "name" value is not a string.
I'd propose something like this instead, to match the other serialization method signatures:
The text was updated successfully, but these errors were encountered: