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
#import <Foundation/Foundation.h> | |
@interface A : NSObject | |
- (void)doThingWithObject:(id)o completion:(void(^)(void))completionHandler; | |
@end | |
@implementation A | |
- (void)doThingWithObject:(id)o completion:(void(^)(void))completionHandler | |
{ | |
NSLog(@"object: %@", o); |
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
Wrong: | |
__weak id obj; | |
dispatch_async(queue, ^() { | |
[obj doSomething]; | |
[obj doSomethingElse]; <- can turn to nil at any point, should store in strong at beggining of block | |
[obj doSomethingElse2]; | |
}); | |
Ok: |
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
With 10.8 SDK, `#define OBJC_OLD_DISPATCH_PROTOTYPES 0` at the top of your file or PCH to get errors if you use objc_msgSend without a cast. |
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
typedef NS_ENUM(NSInteger, kErrorCode) { | |
kErrorCodeInternal = 431432, | |
}; | |
//! generate error and log it. | |
extern NSError *pixle_NSErrorMake(NSString *message, NSUInteger code, NSDictionary *aUserInfo, SEL selector); | |
#define AssertTrueOrReturnBlock(condition, block) do{ NSAssert((condition), @"Invalid condition not satisfying: %s", #condition);\ | |
if(!(condition)) { block(pixle_NSErrorMake([NSString stringWithFormat:@"Invalid condition not satisfying: %s", #condition], kErrorCodeInternal, nil, _cmd)); return;} }while(0) | |
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
#define SafeCall(arg, methodToCall) (arg !=[NSNull null]) ? [arg methodToCall] : nil | |
int optionalValue = SafeCall([response valueForKey:@"number"], intValue); |
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
[UIView transitionWithView:cell.imageView duration:0.25f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ | |
cell.imageView.image = decompressedThumbnail; | |
} completion:nil]; |
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
//! for gesture recognizer support in cocos2d use https://github.com/krzysztofzablocki/CCNode-SFGestureRecognizers | |
- (void)handlePanGesture:(UIPanGestureRecognizer*)gestureRecognizer | |
{ | |
CGPoint location = [[CCDirector sharedDirector] convertToGL:[gestureRecognizer locationInView:gestureRecognizer.view]]; | |
static CGPoint oldLocation; | |
//! this will make sure that oldLocation is initialized | |
if (gestureRecognizer.state != UIGestureRecognizerStateBegan) { | |
//! we need to calculate angle difference between previous position and current one in regards to dial center | |
CGPoint firstDir = ccpSub(oldLocation, dial.position); |
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)dealloc { | |
[percentGender release]; | |
[percentHisto release]; | |
[percentPS release]; | |
[percentSmoke release]; | |
[percentGender dealloc]; | |
[percentHisto dealloc]; | |
[percentPS dealloc]; | |
[percentSmoke dealloc]; | |
percentGender = nil; |
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
CGContextRef bitmapContext = CGBitmapContextCreate(NULL, | |
rect.size.width, | |
rect.size.height, | |
CGImageGetBitsPerComponent(imageRef), | |
CGImageGetBytesPerRow(imageRef), | |
CGImageGetColorSpace(imageRef), | |
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little); |