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
dispatch_source_t _timer; | |
_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)); | |
dispatch_source_set_timer(_timer, | |
dispatch_walltime(NULL, <#timeout#> * NSEC_PER_SEC), | |
1 * NSEC_PER_SEC, // this doenst really matter | |
<# 0.01 (tolerance) #> * NSEC_PER_SEC); | |
dispatch_source_set_event_handler(_timer, ^{ | |
dispatch_source_cancel(_timer); // cancel the repeat |
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
+ (NSArray *)arrayOfClassNamesFilteredByPredicate:(NSPredicate *)predicate | |
{ | |
int numClasses; | |
Class *classes = NULL; | |
classes = NULL; | |
numClasses = objc_getClassList(NULL, 0); | |
if (numClasses < 1 ) return nil; | |
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
+ (NSArray *)arrayOfClassObjectsFilteredByPredicate:(NSPredicate *)predicate | |
{ | |
int numClasses; | |
Class *classes = NULL; | |
classes = NULL; | |
numClasses = objc_getClassList(NULL, 0); | |
if (numClasses < 1 ) return nil; | |
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
+ (NSArray *)subclassesOfClass:(Class)parentClass | |
{ | |
int numClasses = objc_getClassList(NULL, 0); | |
Class *classes = NULL; | |
classes = (__unsafe_unretained Class *)malloc(sizeof(Class) * numClasses); | |
numClasses = objc_getClassList(classes, numClasses); | |
NSMutableArray *result = [NSMutableArray array]; | |
for (NSInteger i = 0; i < numClasses; i++) |
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
NSDate *birthday = value; | |
NSDate *now = [NSDate date]; | |
NSDateComponents *ageComponents = [[NSCalendar currentCalendar] | |
components:NSYearCalendarUnit | |
fromDate:birthday | |
toDate:now | |
options:0]; | |
NSInteger age = [ageComponents year]; |
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
// Native... | |
NSCharacterSet* illegalFileNameCharacters = [NSCharacterSet characterSetWithCharactersInString:@"/\\?%*|\"<>"]; | |
NSString *sanitized = [[fileName componentsSeparatedByCharactersInSet:illegalFileNameCharacters] componentsJoinedByString:@""]; | |
// With Overline (negative matching) | |
NSString *sanitized = [fileName stringByReplacingOccurrencesOfRegExpPattern:@"[^a-zA-Z0-9_\\+\\-]+" withString:@"_" |
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
+ (NSArray *)classPropertyList | |
{ | |
// Get array of all property names | |
unsigned int count; | |
objc_property_t *props = class_copyPropertyList(self, &count); | |
NSMutableArray *propNames = [NSMutableArray array]; | |
for (int i=0; i<count; i++) | |
{ | |
NSString *p = [NSString stringWithUTF8String:property_getName(props[i])]; | |
[propNames addObject:p]; |
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
// FOR CATEGORIES (From same class into same class) | |
// `swizzle()` allows replacing methods in a Category while still leaving access | |
// to the original akin to `super` for subclasses | |
// INJECT/REPLACE (loses original) | |
void (^inject)(Class, SEL, SEL) = ^(Class c, SEL orig, SEL new){ | |
Method newMethod = class_getInstanceMethod(c, new); | |
class_replaceMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)); | |
}; |
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 *)imageOfRibbonBGWithFrame:(CGRect)frame | |
{ | |
CGImageRef bgSolid = [super imageOfRibbonBGWithFrame:frame].CGImage; | |
CGImageRef holes = [super imageOfRibbonDotsWithFrame:frame].CGImage; | |
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(holes), | |
CGImageGetHeight(holes), | |
CGImageGetBitsPerComponent(holes), | |
CGImageGetBitsPerPixel(holes), | |
CGImageGetBytesPerRow(holes), |
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
// iOS >=8 | |
NSOperatingSystemVersion ios8_0_0 = (NSOperatingSystemVersion){8, 0, 0}; | |
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:ios8_0_0]) { | |
// iOS 8 logic | |
} else { | |
// iOS 7 and below logic | |
} | |
// iOS <=7 |