This file contains hidden or 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
// Presentation Layer Hit Test | |
// Source: WWDC2014 Session 236 | |
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event | |
{ | |
CGPoint pointInSuperview = [self convertPoint:point toView:self.superview]; | |
CGPoint presentationLayerPoint = [self.layer.presentationLayer convertPoint:pointInSuperview fromLayer:self.superview.layer]; | |
return [super hitTest:presentationLayerPoint withEvent:event]; | |
} |
This file contains hidden or 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
/** | |
Provides the ability to verify key paths at compile time. | |
If "keyPath" does not exist, a compile-time error will be generated. | |
Example: | |
// Verifies "isFinished" exists on "operation". | |
NSString *key = SQKeyPath(operation, isFinished); | |
// Verifies "isFinished" exists on self. |
This file contains hidden or 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
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
UITableViewCell *cell = | |
[tableView dequeueReusableCellWithIdentifier:REUSABLE_CELL_ID]; | |
UILabel *label = (UILabel *)[cell viewWithTag:VIEW_TAG]; | |
Model *someModel = [self getModelFromIndexPath:indexPath]; | |
// `takeUntil:` makes the RACObserve() signal complete (and thus breaks the subscription) | |
// when the cell is recycled. |
This file contains hidden or 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
// Source: WWDC 2013 Session 228 | |
CFMutableStringRef string = (__bridgeCFMutableStringRef)[@"Hello!こんにちは!สวสัดี!مرحبا!您好!" mutableCopy]; | |
CFStringTransform(string, NULL, kCFStringTransformToLatin, NO); | |
// Hello! kon'nichiha! swạsdī! mrḥbạ! nín hǎo! | |
CFStringTransform(string, NULL, kCFStringTransformStripCombiningMarks, NO); | |
// Hello! kon'nichiha! swasdi! mrhba! nin hao! |
This file contains hidden or 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
/* | |
Extract date from natural language string | |
Source: WWDC2012 Session 215 - Text and Linguistic Analysis | |
*/ | |
NSDataDetector *dateDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeDate error:nil]; | |
NSString *dateString = @"13th September 1986 11:59pm"; | |
NSTextCheckingResult *result = [dateDetector firstMatchInString:dateString | |
options:0 | |
range:NSMakeRange(0, [dateString length])]; |
This file contains hidden or 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
// Source: WWDC 2012 Session 216 | |
// Advanced Appearance Customization on iOS | |
// Rather useful when your button is smaller than the golden 44 points | |
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event | |
{ | |
CGFloat widthDelta = 44.0 - bounds.size.width; | |
CGFloat heightDelta = 44.0 - bounds.size.height; | |
CGRect bounds = CGRectInset(self.bounds, -0.5 * widthDelta, -0.5 * heightDelta); | |
return CGRectContainsPoint(bounds, point); |
This file contains hidden or 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
NSNumber *value; | |
value = @'X'; // char | |
value = @12345 // int | |
value = @12345ul // unsigned long | |
value = @12345ll // long long | |
value = @123.45f // float | |
value = @123.45 // double | |
value = @YES // BOOL |
This file contains hidden or 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
/* | |
Source: WWDC2012 Modern Objective-C talk | |
How to get a constant literal container to work. | |
*/ | |
@implementation MyClass | |
static NSArray *thePlanets; | |
+ (void)initialize { |
This file contains hidden or 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
/* | |
Source: Building Concurrent User Interfaces on iOS | |
WWDC2012 Session 211 by Andy Matuschak | |
*/ | |
NSOperationQueue *queue = [[NSOperation alloc] init]; | |
NSBlockOperation *op = [[NSBlockOperation alloc] init]; | |
__weak NSBlockOperation *weakOp = op; | |
[op addExecutionBlock:^{ | |
for (int i = 0; i < 10000; i++) { |