Skip to content

Instantly share code, notes, and snippets.

View flexaddicted's full-sized avatar

Lorenzo B. flexaddicted

View GitHub Profile
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[NSClassFromString(@"WebView") _enableRemoteInspector];
// or [NSClassFromString(@"WebView") performSelector:@selector(_enableRemoteInspector)];
// if the compiler will complain
}
UIImage* image = [UIImage imageNamed:@"my_image"];
[self.myButton setImage:image forState:UIControlStateNormal];
[self.myButton setTitle:@"My button" forState:UIControlStateNormal];
UITapGestureRecognizer* tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewTapped:)];
tapGestureRecognizer.numberOfTapsRequired = 1;
self.myButton.imageView.userInteractionEnabled = YES;
[self.myButton.imageView addGestureRecognizer:tapGestureRecognizer];
[[tapGestureRecognizer view] superview];
_.map([1, 2, 3], function(num) { return num * 3; });
function(num) { return num * 3; }
// NSArray+FAPMap.h
typedef id(^MapBlock)(id item);
@interface NSArray (FAPMap)
- (NSArray*)fap_map:(MapBlock)mapBlock;
@end
// NSArray+FAPMap.m
// 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);
}];
- (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;
}];
}
// in NetworkFetcher class
- (void)requestCompleted {
if(self.completionHandler) {
// invoke the block with data
self.completionHandler(self.downloadedData);
}
// break the retain cycle
self.completionHandler = nil;
}