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)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 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 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 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 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
myView.layer.shadowOpacity = 0.8; | |
myView.layer.shadowRadius = 5.0; | |
myView.layer.shadowOffset = CGSizeZero; | |
myView.layer.shadowPath = [UIBezierPath bezierPathWithRect:myView.layer.bounds].CGPath; |
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)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration{ | |
static float prevX=0, prevY=0; | |
float accelX = acceleration.x * kFilterFactor + (1- kFilterFactor)*prevX; | |
float accelY = acceleration.y * kFilterFactor + (1- kFilterFactor)*prevY; | |
prevX = accelX; | |
prevY = accelY; | |
pitch = accelX; | |
} |
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
// | |
// Lightning.h | |
// Trundle | |
// | |
// Created by Robert Blackwood on 12/1/09. | |
// Copyright 2009 Mobile Bros. All rights reserved. | |
// | |
#import "cocos2d.h" |
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 NSLogFrame(description,aFrame) NSLog(@"%@ - {%0.0f:%0.0f}{%0.0f:%0.0f}", description, aFrame.origin.x, aFrame.origin.y, aFrame.size.width, aFrame.size.height); | |
#define NSLogPoint(description,aFrame) NSLog(@"%@ - {%0.0f:%0.0f}{%0.0f:%0.0f}", description, aFrame.origin.x, aFrame.origin.y, aFrame.size.width, aFrame.size.height); |
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
@interface LoaderURL : NSObject | |
{ | |
NSMutableData *responseData; | |
NSURLConnection *connectionXML; | |
} | |
@property (nonatomic, copy) NSString *xmlFileName; | |
- (BOOL) updateFile; |
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 CMLog(format, ...) NSLog(@"%s:%@", __PRETTY_FUNCTION__,[NSString stringWithFormat:format, ## __VA_ARGS__]); | |
#define MARK CMLog(@"%s", __PRETTY_FUNCTION__); | |
#define START_TIMER NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate]; | |
#define END_TIMER(msg) NSTimeInterval stop = [NSDate timeIntervalSinceReferenceDate]; CMLog([NSString stringWithFormat:@"%@ Time = %f", msg, stop-start]); | |