(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| guard sourceUrl.matches([".dat", ".csv"]) else { | |
| print("Extension not allowed!") | |
| } | |
| // do your stuff here |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| // CDBaseManagedObject.h | |
| @interface CDBaseManagedObject : NSManagedObject | |
| + (NSString *)entityName; | |
| + (instancetype)insertNewObjectIntoContext:(NSManagedObjectContext *)context; | |
| @end | |
| // CDBaseManagedObject.m | |
| @implementation CDBaseManagedObject |
| // NSManagedObject+CDAdditions.h | |
| @interface NSManagedObject (CDAdditions) | |
| + (NSString *)CDAdditionsEntityName; | |
| + (instancetype)CDAdditionsInsertNewObjectIntoContext:(NSManagedObjectContext *)context; | |
| @end | |
| // NSManagedObject+CDAdditions.m | |
| @implementation NSManagedObject (CDAdditions) |
| // how to use NetworkRequest class | |
| NSURL *urlRequest = [NSURL URLWithString:@"someurlhere"]; | |
| NetworkRequest *request = [[NetworkRequest alloc] initWithURL:urlRequest]; | |
| [request performWithCompletionHandler:^(NSData *data) { | |
| NSLog(@"Hello world!!!"); | |
| }]; |
| // NetworkRequest.h | |
| typedef void(^NetworkRequestCompletionHandler)(NSData *data); | |
| @interface NetworkRequest : NSObject | |
| @property (nonatomic, strong, readonly) NSURL* url; | |
| - (id)initWithURL:(NSURL*)url; | |
| - (void)performWithCompletionHandler:(NetworkRequestCompletionHandler)completionHandler |
| // in NetworkFetcher class | |
| - (void)requestCompleted { | |
| if(self.completionHandler) { | |
| // invoke the block with data | |
| self.completionHandler(self.downloadedData); | |
| } | |
| // break the retain cycle | |
| self.completionHandler = nil; | |
| } |
| - (void)downloadData { | |
| NSURL *url = [NSURL URLWithString:@"someurlhere"]; | |
| NetworkFetcher *networkFetcher = [[NetworkFetcher alloc] initWithURL:url]; | |
| [networkFetcher startWithCompletionHandler:^(NSData *data){ | |
| NSLog(@"Request URL %@ finished", networkFetcher.url); | |
| _fetchedData = data; | |
| }]; | |
| } |
| // how to use NSArray+FAPMap category | |
| NSArray* toMapArray = @[@1, @2, @3]; | |
| NSArray* mappedArray = [toMapArray fap_map:^id(id item) { | |
| NSNumber* itemAsNumber = (NSNumber*)item; | |
| int resultValue = [itemAsNumber integerValue] * 3; | |
| return @(resultValue); | |
| }]; |