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
@implementation NSObject (PerformBlockAfterDelay) | |
- (void)performBlock:(void (^)(void))block | |
afterDelay:(NSTimeInterval)delay | |
{ | |
block = [[block copy] autorelease]; | |
[self performSelector:@selector(fireBlockAfterDelay:) | |
withObject:block | |
afterDelay:delay]; | |
} |
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
-(NSDate *) lastMondayBeforeDate:(NSDate*)timeStamp { | |
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; | |
NSDateComponents *comps = | |
[gregorian components:NSWeekdayCalendarUnit fromDate:timeStamp]; | |
NSInteger weekday = [comps weekday]; | |
weekday = weekday==1 ? 6 : weekday-2; // start with 0 on Monday rather than 1 on Sunday | |
NSTimeInterval secondsSinceMondayMidnight = | |
(NSUInteger) [timeStamp timeIntervalSince1970] % 60*60*24 + | |
weekday * 60*60*24; | |
return [timeStamp dateByAddingTimeInterval:-secondsSinceMondayMidnight]; |
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
// override this method to get a great log output | |
// to show how the view is resized when rotating, | |
// calling sizeToFit and other methods that affect the frame | |
- (void) setFrame:(CGRect)frame { | |
[super setFrame:frame]; | |
NSLog(@"%@ - %@", NSStringFromSelector(_cmd), NSStringFromCGRect(frame)); | |
} |
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
// Make a picture browser, just like in the Photo app | |
// **With only six additional lines of code!** | |
// in viewDidLoad: | |
self.tableView.transform = CGAffineTransformMakeRotation(-M_PI/2); // turn the table 90° anti-clockwise | |
self.tableView.showsVerticalScrollIndicator = NO; | |
self.tableView.pagingEnabled = YES; |
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
// Override this method in any class to get a pretty list of | |
// all methods that are being called - very useful. | |
// Try it on the AppDelegate for example | |
-(BOOL)respondsToSelector:(SEL)aSelector { | |
printf("The spy says: %s\n", [NSStringFromSelector(aSelector) UTF8String]); | |
return [super respondsToSelector:(aSelector)]; | |
} |
NewerOlder