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
- (NSMutableData *)mutableRGBAData { | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
CGSize scaledSize = (CGSize){ | |
.width = self.size.width * self.scale, | |
.height = self.size.height * self.scale, | |
}; | |
NSUInteger const bytesPerPixel = 4; | |
NSUInteger const bitsPerComponent = 8; |
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
#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
+ (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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>DVTConsoleDebuggerInputTextColor</key> | |
<string>0.715709 0.129913 0.185409 1</string> | |
<key>DVTConsoleDebuggerInputTextFont</key> | |
<string>Menlo-Regular - 13.0</string> | |
<key>DVTConsoleDebuggerOutputTextColor</key> | |
<string>1 1 1 1</string> |
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
// Network request failed, due to lost internet conenction... | |
OCAErrorRecoveryAttempter *recoveryAttempter = [[OCAErrorRecoveryAttempter alloc] init]; | |
// Recovery suggestion will be be presented together with error message. | |
recoveryAttempter.recoverySuggestion = @"Make sure you are connected to the Internet and try again."; | |
// Creates reactive recovery option and chains an invocation to [self start]. | |
[[recoveryAttempter addRecoveryOptionWithTitle:@"Retry"] invoke:OCAInvocation(self, start)]; |
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 triggers correct KVO insertion notification: | |
[parent.mutableChildren addObject:@"Child"]; |
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 *)clockForHour:(NSUInteger)hour { | |
NSArray *clocks = @[ @"🕛", @"🕐", @"🕑", @"🕒", @"🕓", @"🕔", | |
@"🕕", @"🕖", @"🕗", @"🕘", @"🕙", @"🕚" ]; | |
NSUInteger index = hour % clocks.count; | |
return [clocks objectAtIndex:index]; | |
} |
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; | |
@interface NSObject (ThreadSafeProxy) | |
- (instancetype)threadSafe; | |
@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
import UIKit | |
import CoreText | |
extension UIFont { | |
typealias Feature = (type: Int, selector: Int) | |
struct Features { | |
static var ProportionalNumbers: Feature = (kNumberSpacingType, kProportionalNumbersSelector) | |
static var AlternatePunctuation: Feature = (kCharacterAlternativesType, 1) // Magic! | |
} |