Last active
August 29, 2015 14:15
-
-
Save lifely/0005075d9ba80e827827 to your computer and use it in GitHub Desktop.
Fail or Continue - Paradigme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSArray *developerList = nil; | |
if (!responseObject || !(developerList = [responseObject objectForKey:@"list"]) || | |
![developerList isKindOfClass:[NSArray class]]) | |
return ; // call error/failure block | |
NSArray *developers = [SFService prepareObjectFromResponse:developerList forObjectClass:[SFDeveloper class]]; | |
NSLog(@"[SUCCESS][SFService-api] Action /trombi/ : \n%@", developers); |
Three years later, lifely replies !
So, i agree with what you were saying and it's all fine. However the code on this gist was more of an concept example than a real issue.
I was mostly referring about the way to organise, the flow of your code. In order to achieve a more linear reading experience, i usually write my code like the above :
- request
- check for failure or (request, assign and check for failure on the same line)
- handle failure
- rest of the function is the logical code of the function
I have moved on a little with swift and have more background on it now, so i see what i was doing wrong and what can be done now, i still have to figure some things but i have time.
However i'll point out one link: http://ericasadun.com/2015/02/16/swift-linearizing-code/ by erica sadun, it's exactly what i was trying to reproduce and she probably explain it better than i do.
Thanks, cc @apouche
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
isKindOfClass:[NSArray class]
doesn't exist in swift, you should test for object conversion insteadAlso creating objects based on their class can't be achieved in full swift, but can easily be done by using objc runtime.
I personally use an ObjectFactory. So you can then do things like: