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
extension UIColor { | |
convenience init(displayP3Hue hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat = 1) { | |
/// HSB to RGB conversion doesn’t depend on color space, so we can use default UIColor space. | |
let converter = UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: 1) | |
var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0 | |
converter.getRed(&red, green: &green, blue: &blue, alpha: nil) | |
self.init(displayP3Red: red, green: green, blue: blue, alpha: alpha) |
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)enumerateAdoptedProtocolsOfProtocol:(Protocol *)protocol usingBlock:(void(^)(Protocol *adoptedProtocol))block { | |
unsigned int adoptedCount = 0; | |
Protocol * __unsafe_unretained *adoptedProtocolList = protocol_copyProtocolList(protocol, &adoptedCount); | |
if (adoptedProtocolList) { | |
for (NSUInteger index = 0; index < adoptedCount; index++) { | |
Protocol *adoptedProtocol = adoptedProtocolList[index]; | |
block(adoptedProtocol); | |
} | |
free(adoptedProtocolList); |
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
# This will load Telekinesis from debugger (don’t forget to use correct path). | |
# You can use this debugger command as breakpoint handler on UIApplicationMain. | |
expr (void *)dlopen("/path/to/Telekinesis.framework/Telekinesis", 0x2) | |
# You can also check for class "TeleHub", to make sure it’s not loaded twice: | |
expr (Class)NSClassFromString(@"TeleHub") == nil ? (void *)dlopen("/path/to/Telekinesis.framework/Telekinesis", 0x2) : ((void*)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
#import <Foundation/Foundation.h> | |
typedef void(^KVObservingBlock)(id value, NSDictionary *change); | |
@interface KVObserver : NSObject | |
- (instancetype)initWithBlock:(KVObservingBlock)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
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { | |
NSUInteger section = ... | |
CGRect rect = [self.tableView rectForSection:section]; | |
// Include content inset | |
rect.origin.y -= self.tableView.contentInset.top; | |
// Restore previous offset and animate to destination | |
CGPoint offset = self.tableView.contentOffset; |
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
#if !defined(NS_BLOCK_ASSERTIONS) | |
#define MTKAssert(CONDITION, MESSAGE, ...)\ | |
if ( ! (CONDITION) && (( [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] file:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ description:MESSAGE, ##__VA_ARGS__], YES)) ) | |
#else | |
#define MTKAssert(CONDITION, MESSAGE, ...)\ | |
if ( ! (CONDITION) && (( NSLog(@"*** Assertion failure in %s, %s:%d, Condition not satisfied: %s, reason: '" MESSAGE "'", __PRETTY_FUNCTION__, __FILE__, __LINE__, #CONDITION, ##__VA_ARGS__), YES)) ) |
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
CGFloat CGFloatAdjustToScreenScale(CGFloat value, NSRoundingMode mode) { | |
CGFloat (*roundingFunction)(CGFloat); | |
switch (mode) { | |
case NSRoundPlain: roundingFunction = &roundf; break; | |
case NSRoundUp: roundingFunction = &ceilf; break; | |
case NSRoundDown: roundingFunction = &floorf; break; | |
case NSRoundBankers:roundingFunction = &roundf; break; | |
} | |
CGFloat scale = [[UIScreen mainScreen] scale]; | |
CGFloat result = roundingFunction(value * scale) / scale; |
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
- (NSString *)stringByDeletingHTML { | |
// Delete HTMl tags. | |
/// http://stackoverflow.com/questions/277055/remove-html-tags-from-an-nsstring-on-the-iphone | |
NSRange range; | |
NSMutableString *string = [self mutableCopy]; | |
while ((range = [string rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound) | |
[string deleteCharactersInRange:range]; | |
// Replace escaped sequences. | |
NSDictionary *escapes = @{ |
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
2013-03-22 21:26:36.231 TeeVee[86457:c07] *** -[__NSCFCalendar components:fromDate:]: date cannot be nil | |
I mean really, what do you think that operation is supposed to mean with a nil date? | |
An exception has been avoided for now. | |
A few of these errors are going to be reported with this complaint, then further violations will simply silently do whatever random thing results from the nil. | |
Here is the backtrace where this occurred this time (some frames may be missing due to compiler optimizations): | |
( | |
0 CoreFoundation 0x0283da75 -[__NSCFCalendar components:fromDate:] + 85 | |
1 TeeVee 0x00037e0e -[TVUpcomingEpisodeViewController viewDidLoad] + 3886 | |
... |
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
// How do you implement lazy loading getters? | |
- (NSString *)title { | |
if ( ! self->_title) { | |
NSString *string = @"lazy loaded"; | |
// Do some real stuff here... | |
self->_title = string; | |
} | |
return self->_title; | |
} |