-
Notifications
You must be signed in to change notification settings - Fork 0
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
if properties[@"image_url"] is NSNull, then EVStory will crash #247
Comments
@jhankin @justinbrunet comment here when you have a chance, I want to know what you guys think |
Same idea as Mantle, though it seems a lot simpler/more readable to me. I did this fairly quickly, though, so it's definitely possible I'm missing something. This shouldn't actually be merged in without a ton more testing, I was just trying to see if this would tag to the commit so you could see the code.
I absolutely agree our parsing needs to be more solid; it shouldn't be crashing under any circumstances. We should a) be testing it, but also b) just have something that is less likely to crash and burn. However, I thought Mantle was borderline un-readable, so I did a quick implementation of what I thought was the general idea of it (code referenced above). Maybe the confusing-ness is because their interface is more powerful, but I think something along the lines of what I did could give us close to what we need without the heavy-handedness of Mantle. |
I agree with all of the above. I also think Mantle is kind of ugly, but at the same time, I'm fascinated by the idea of the NSValueTransformer. We could have generalized instances/subclasses of NSValueTransformer to convert certain common things (numbers, amounts, what have you) both back and forth, which would (theoretically) give us the ability to have Justin, I think your code makes sense but I'm not that crazy about the idea of doing voodoo with mapping selectors and whatnot -- especially because it seems like each property needs its own mapping method, rather than being able to factor out commonalities (like |
Isn't Mantle doing the exact same thing? They have a URLJSONTransformer method, a HTMLURLJSONTransformer method, a stateJSONTransformer method, etc for every property. The only difference is the ones that are making a URL, for example, then call the same method within the method for each property, which would be easy enough to factor out. As for mapping selectors voodoo, if you dig deeper into Mantle, it begins playing with the objective-c runtime to do the same voodoo. It's just hidden a few classes up (and the voodoo part here should be too, I was just trying to make it obvious what it was doing). |
Maybe we should just try throwing Mantle in later and see how it plays out of the box with our setProperties methods and subclassing chains. |
Fair point. I guess any time we're going to be making some kind of automagic parsing code, there's gonna be some voodoo involved. It does make sense to try throwing Mantle in and see how things go before we spend a lot of our (precious) time reinventing the wheel. |
Taking it another level, a Mapping itself, is almost enough to be a Transformer, i.e. when I write a Mapping for an EVUser, it itself can automatically be used as a UserTransformer for an EVPayment's mapping. The only thing we would need to add are edge case functions for when shit is nil or NSNull
|
I think it is possible to determine the type of a property, but I also think it's pretty complex. Not entirely sure, though, would need to mess around. |
It's definitely not pretty. See http://stackoverflow.com/questions/769319/how-to-detect-a-property-return-type-in-objective-c for details. As an example, I put the following into
And what came out looked sort of like this:
|
Well, it could be worse I suppose. |
That doesn't seem too bad. Just get the first element in attr, call NSClassFromString on it, and then go find the Transformer for that Class |
Plus parse for the encoding types of the non-object ones. All the BOOLs On Wed, Aug 21, 2013 at 4:51 PM, Sean Yu [email protected] wrote:
Joe Hankin |
EVStory.m line 246
Trying to make a NSURL out of an NSNull will crash execution. This brings up the larger problem of us having a brittleness in our parsing code. We need to come up with a strategy that makes our data parsing more robust.
I recommend a strategy similar to Mantle. They created a mapping strategy where one can go from NSObject property to NSDictionary key=>value. A 'transformer' can be provided which automatically maps to common types such as NSURL. The code path is the same, so one only needs to write type safety checks for NSNull, etc once. I found their interface slightly confusing, but that might be because it's very powerful. However, the mapping idea is a good one, and if we had that functionality, we can significantly reduce the number of crashes we have due to Vine-API incompatibilities.
Lemme know what you think!
PS
Using an Issue on Github, because I believe you can make commits with issue numbers, and directly create Pulls out of them, which is pretty cool. Just wanted to try it out
The text was updated successfully, but these errors were encountered: