This file contains hidden or 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
| class Moral: Developer { } | |
| class UncleBob: Developer { | |
| func programmingLanguage() -> String { | |
| return "Java" | |
| } | |
| } | |
| var moral = Moral() | |
| moral.programmingLanguage() |
This file contains hidden or 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
| class CommonPattern: UIViewController { | |
| func openMenu() {…} | |
| func selectOption(option: NSUInteger) {…} | |
| } | |
| class HomeApp: CommonPattern { | |
| func viewDidLoad() { | |
| super.viewDidLoad(){ | |
| openMenu() | |
| } |
This file contains hidden or 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
| protocol Developer { | |
| func programmingLanguage() -> String | |
| } | |
| extension Developer { | |
| func programmingLanguage() -> String { | |
| return "iOS" | |
| } | |
| } |
This file contains hidden or 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
| /// @return RACSignal Next: (id) a 'class' instance/object | |
| + (RACSignal *)parseJSONDictionary:(NSDictionary *)JSONDictionary toClass:(Class)class { | |
| return [[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { | |
| NSError *error; | |
| id model = [MTLJSONAdapter modelOfClass:class fromJSONDictionary:JSONDictionary error:&error]; | |
| if (error) { | |
| [subscriber sendError:error]; | |
| } else { | |
| [subscriber sendNext:model]; |
This file contains hidden or 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
| /// @return RACSignal Next: (NSDictionary *)JSON | |
| + (RACSignal *)getJSONFromRESTPath:(NSString *)path withParams:(NSDictionary *)params { | |
| path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; | |
| RACSignal *signal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { | |
| AFURLConnectionOperation *task = [[AMGNetworkManager sharedInstance].manager | |
| GET:path | |
| parameters:params | |
| success:^(AFHTTPRequestOperation *operation, id responseObject) { |
This file contains hidden or 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
| + (RACSignal *)performRequestWithMethod:(AMGRESTManagerHTTPMethod)httpMethod | |
| toRESTPath:(NSString *)path | |
| withParams:(NSDictionary *)params | |
| resultObjectClass:(Class)class | |
| isArray:(BOOL)isArray { | |
| RACSignal *JSONSignal = nil; | |
| switch (httpMethod) { | |
| case AMGRESTManagerHTTPMethodGET: | |
| JSONSignal = [AMGNetworkManager getJSONFromRESTPath:path withParams:params]; | |
| break; |
This file contains hidden or 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
| /// @return RACSignal Next: (AMGModelItems *) | |
| + (RACSignal *)questions { | |
| NSString *apiPath = [AMGConstantsManager APIPathQuestions]; | |
| return [AMGRESTManager performRequestWithMethod:AMGRESTManagerHTTPMethodGET | |
| toRESTPath:apiPath | |
| withParams:nil | |
| resultObjectClass:[AMGModelItems class] | |
| isArray:YES]; | |
| } |
This file contains hidden or 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
| + (RACSignal *)questions { | |
| return [AMGQuestionsManager questions]; | |
| } |
This file contains hidden or 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
| [[AMGAPI questions] subscribeNext:^(NSArray *questions) { | |
| [questions enumerateObjectsUsingBlock:^(AMGModelItems * _Nonnull questions, NSUInteger idx, BOOL * _Nonnull stop) { | |
| NSLog(@"Questions %lu: %@ \n", (unsigned long)idx, questions.title); | |
| }]; | |
| }]; |
This file contains hidden or 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
| extension Array { | |
| func reducee<T>(initial: T, combine: (T, Element) -> T) -> T { | |
| var result = initial | |
| for x in self { | |
| result = combine(result, x) | |
| } | |
| return result | |
| } | |
| } |