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 UIView (JRHierarchyAdditions) | |
- (void)bringToFront; | |
- (void)sendToBack; | |
@end | |
@implementation UIView (JRHierarchyAdditions) | |
- (void)bringToFront { | |
[[self superview] bringSubviewToFront:self]; | |
} |
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
//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: |
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
@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]; |
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 NSArray (JRAdditions) | |
- (id) safeObjectAtIndex:(NSUInteger)index; | |
@end | |
@implementation NSArray (JRAdditions) | |
- (id) safeObjectAtIndex:(NSUInteger)index { | |
@synchronized(self) { |
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 JRObject : NSObject @end | |
@implementation JRObject | |
- (void)doesNotRecognizeSelector:(SEL)selector { | |
NSLog(@"Attempted to invoke %s on %@", selector, self); | |
} | |
@end |
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 NSArray(JRAdditions) | |
- (id)jr_objectAtIndex:(long long)index { | |
NSUInteger realIndex = index; | |
if(index < 0) { | |
realIndex = [self count] - (+index); | |
} | |
return [self objectAtIndex:realIndex]; | |
} |
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)printRecursivelyUpTo:(NSUInteger)max { | |
__block dispatch_block_t block; | |
__block NSUInteger iterator = 0; | |
dispatch_block_t b = ^{ | |
if(iterator == max) return; | |
NSLog(@"%u", iterator); | |
++iterator; | |
block(); | |
}; |
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 NSLock (JRAdditions) | |
- (void)lockWithBlock:(dispatch_block_t)block; | |
@end |
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 void (^JRIterationBlock)(NSUInteger index); | |
static inline void invokeBlockIterativelyUsingRange(JRIterationBlock block, NSRange rng) { | |
NSParameterAssert(block); | |
for(NSUInteger i = rng.location; i < NSMaxRange(rng); ++i) { | |
block(i); | |
} | |
} | |
@implementation NSNumber (BlockAdditions) |
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 NSCountedSet (JRCountedSetAdditions) | |
- (NSArray *) objectsWithCount:(NSUInteger) count; | |
@end |
OlderNewer