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
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
[NSClassFromString(@"WebView") _enableRemoteInspector]; | |
// or [NSClassFromString(@"WebView") performSelector:@selector(_enableRemoteInspector)]; | |
// if the compiler will complain | |
} |
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
_.map([1, 2, 3], function(num) { return num * 3; }); |
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
function(num) { return num * 3; } |
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+FAPMap.h | |
typedef id(^MapBlock)(id item); | |
@interface NSArray (FAPMap) | |
- (NSArray*)fap_map:(MapBlock)mapBlock; | |
@end | |
// NSArray+FAPMap.m |
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
// 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); | |
}]; |
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
- (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; | |
}]; | |
} |
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
// in NetworkFetcher class | |
- (void)requestCompleted { | |
if(self.completionHandler) { | |
// invoke the block with data | |
self.completionHandler(self.downloadedData); | |
} | |
// break the retain cycle | |
self.completionHandler = nil; | |
} |