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
| Nested invocations provide asynchronous callbacks | |
| • Communication between subsystems | |
| -(IBAction)onClick:(NSButton *)sender | |
| { | |
| dispatch_async(account->queue, | |
| ^{ | |
| NSImageRep *image = renderAccountStatement(account); | |
| dispatch_async(dispatch_get_main_queue(),^{ |
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
| Singleton Objects | |
| Lazy initialization is common | |
| @implementation FooController | |
| // #1 | |
| + (FooController *)sharedInstance | |
| { | |
| static dispatch_once_t once; | |
| static FooController *instance; | |
| dispatch_once(&once, ^{ |
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
| - (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)newSize | |
| { | |
| UIGraphicsBeginImageContextWithOptions(newSize, YES, 0.0); | |
| CGRect imageRect = {{0.0, 0.0}, newSize}; | |
| [image drawInRect:imageRect]; | |
| UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); | |
| UIGraphicsEndImageContext(); | |
| return scaledImage; | |
| } |
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
| - (void)viewDidLoad { | |
| //find the UITextField view within searchBar (outlet to UISearchBar) | |
| //and assign self as delegate | |
| for (UIView *view in searchBar.subviews){ | |
| if ([view isKindOfClass: [UITextField class]]) { | |
| UITextField *tf = (UITextField *)view; | |
| tf.delegate = self; | |
| 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
| AudioToolbox.framework | |
| #import <AudioToolbox/AudioServices.h> | |
| Now use this line of code everytime you want to make the phone vibrate: | |
| AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); |
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
| - (void)drawRect:(CGRect)rect | |
| { | |
| CGContextRef context = UIGraphicsGetCurrentContext(); // get current context | |
| // CGFloat object_size = sizeStatus/2; | |
| // CGFloat sx, sy, fsize = object_size; | |
| // sx = rect.size.width - fsize; | |
| // sy = fsize; | |
| // CGContextMoveToPoint(context, sx, sy); |
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
| [self setWantsFullScreenLayout:YES]; | |
| [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES]; | |
| self.navigationController.navigationBar.translucent = YES; | |
| self.navigationController.navigationBar.backgroundColor = [UIColor clearColor]; | |
| self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; | |
| [[UIApplication sharedApplication] setStatusBarHidden:ControlsHidden]; |
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
| NSArray *names = [UIFont familyNames]; | |
| for (NSString *fontName in names) { | |
| NSLog(@"%@:", fontName); | |
| NSArray *fontnames = [UIFont fontNamesForFamilyName:fontName]; | |
| for (NSString *fontNameinFamily in fontnames) { | |
| NSLog(@"-->%@", fontNameinFamily); | |
| } | |
| } | |
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 SomeClassDelegate <NSObject> | |
| - (void) SomeClassSelector:(ParamType*)param; | |
| @end | |
| @interface SomeClass : UIViewController { | |
| id <SomeClassDelegate> delegate; | |
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
| @interface UIImage (TPAdditions) | |
| - (UIImage*)imageScaledToSize:(CGSize)size; | |
| @end | |
| @implementation UIImage (TPAdditions) | |
| - (UIImage*)imageScaledToSize:(CGSize)size { | |
| UIGraphicsBeginImageContext(size); | |
| [self drawInRect:CGRectMake(0, 0, size.width, size.height)]; | |
| UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
| UIGraphicsEndImageContext(); |