Skip to content

Instantly share code, notes, and snippets.

View plantpurecode's full-sized avatar
🎯

Jacob Relkin plantpurecode

🎯
View GitHub Profile
@plantpurecode
plantpurecode / gist:1914668
Created February 26, 2012 07:13
Safe message invocation, untested
@interface JRObject : NSObject @end
@implementation JRObject
- (void)doesNotRecognizeSelector:(SEL)selector {
NSLog(@"Attempted to invoke %s on %@", selector, self);
}
@end
@plantpurecode
plantpurecode / gist:1880242
Created February 22, 2012 00:45
Safe -objectAtIndex: method
@interface NSArray (JRAdditions)
- (id) safeObjectAtIndex:(NSUInteger)index;
@end
@implementation NSArray (JRAdditions)
- (id) safeObjectAtIndex:(NSUInteger)index {
@synchronized(self) {
@plantpurecode
plantpurecode / NSIndexPath+JRAdditions.m
Created January 3, 2012 22:56
A handy category on NSIndexPath.
@implementation NSIndexPath (JRAdditions)
- (NSIndexPath *) indexPathByAddingRows:(NSInteger)rows andSections:(NSInteger)sections {
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:MIN(NSIntegerMax, [self row] + rows)
inSection:MIN(NSIntegerMax, [self section] + sections)];
return newIndexPath;
}
- (NSIndexPath *) indexPathByAddingRows:(NSInteger) rows {
return [self indexPathByAddingRows:rows andSections:0];
@plantpurecode
plantpurecode / gist:1340889
Created November 5, 2011 00:44
Birthday celebration
//GCD way:
double delayInSeconds = (24 * 60) * 60;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self setAge:[self age] + 1];
});
//NSInvocation way:
@interface UIView (JRHierarchyAdditions)
- (void)bringToFront;
- (void)sendToBack;
@end
@implementation UIView (JRHierarchyAdditions)
- (void)bringToFront {
[[self superview] bringSubviewToFront:self];
}