hidden gems in cocoa and cocoa touch - apple inc. · hidden gems in cocoa and cocoa touch scott...
TRANSCRIPT
![Page 1: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/1.jpg)
These are confidential sessions—please refrain from streaming, blogging, or taking pictures
Session 228
Hidden Gems in Cocoa and Cocoa Touch
Scott StevensonSoftware Engineer
![Page 2: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/2.jpg)
Mattt ThompsonNSHipster.com
![Page 3: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/3.jpg)
![Page 4: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/4.jpg)
Xcode
Core Data
UIKit
AppKit
Objective-C
Foundation
Core Animation
![Page 5: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/5.jpg)
Editing and debuggingXcode
![Page 6: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/6.jpg)
XcodeOpen Quickly (Command-Shift-O)
Tip
1
![Page 7: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/7.jpg)
XcodeOpen Quickly (Command-Shift-O)
Tip
1
![Page 8: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/8.jpg)
XcodeOpen Quickly (Command-Shift-O)
Tip
1
![Page 9: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/9.jpg)
XcodeOpen Quickly (Command-Shift-O)
Tip
1
![Page 10: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/10.jpg)
XcodeOpen Quickly (Command-Shift-O)
Tip
1
![Page 11: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/11.jpg)
XcodeOpen Quickly (Command-Shift-O)
Tip
1
![Page 12: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/12.jpg)
XcodeRelated Files
Tip
2
![Page 13: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/13.jpg)
XcodeRelated Files
Tip
2
![Page 14: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/14.jpg)
Breakpoint ActionsXcode
• Less time recompiling• Log message, trigger command• Conditionals
Tip
3
![Page 15: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/15.jpg)
Debug descriptionXcode Tip
4
![Page 16: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/16.jpg)
Debug descriptionXcode
• Verbose debugging string
Tip
4
![Page 17: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/17.jpg)
Debug descriptionXcode
• Verbose debugging string- (NSString *)debugDescription {
Tip
4
![Page 18: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/18.jpg)
Debug descriptionXcode
• Verbose debugging string- (NSString *)debugDescription { return @"A reeeeeeeaaaalllly long debug string with nerdy details.";
Tip
4
![Page 19: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/19.jpg)
Debug descriptionXcode
• Verbose debugging string- (NSString *)debugDescription { return @"A reeeeeeeaaaalllly long debug string with nerdy details.";}
Tip
4
![Page 20: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/20.jpg)
Debug descriptionXcode
• Verbose debugging string- (NSString *)debugDescription { return @"A reeeeeeeaaaalllly long debug string with nerdy details.";}
(lldb) po self.rootViewController
Tip
4
![Page 21: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/21.jpg)
Debug descriptionXcode
• Verbose debugging string- (NSString *)debugDescription { return @"A reeeeeeeaaaalllly long debug string with nerdy details.";}
(lldb) po self.rootViewControllerA reeeeeeeaaaalllly long debug string with nerdy details.
Tip
4
![Page 22: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/22.jpg)
Debug descriptionXcode
• Verbose debugging string- (NSString *)debugDescription { return @"A reeeeeeeaaaalllly long debug string with nerdy details.";}
(lldb) po self.rootViewControllerA reeeeeeeaaaalllly long debug string with nerdy details.
•Use with Breakpoint Actions!
Tip
4
![Page 23: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/23.jpg)
Recursive descriptionXcode Tip
5
![Page 24: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/24.jpg)
Recursive descriptionXcode
<UINavigationItemView: 0x757be70; frame = (350 9; 68 27); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x757bf60>>
Tip
5
![Page 25: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/25.jpg)
Recursive descriptionXcode
<UINavigationItemView: 0x757be70; frame = (350 9; 68 27); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x757bf60>><UINavigationButton: 0x7586ed0; frame = (7 7; 51 30); opaque = NO; layer = <CALayer: 0x75870b0>>
Tip
5
![Page 26: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/26.jpg)
Recursive descriptionXcode
<UINavigationItemView: 0x757be70; frame = (350 9; 68 27); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x757bf60>><UINavigationButton: 0x7586ed0; frame = (7 7; 51 30); opaque = NO; layer = <CALayer: 0x75870b0>> | <UIImageView: 0x7588ed0; frame = (0 0; 51 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7588f30>>
Tip
5
![Page 27: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/27.jpg)
Recursive descriptionXcode
<UINavigationItemView: 0x757be70; frame = (350 9; 68 27); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x757bf60>><UINavigationButton: 0x7586ed0; frame = (7 7; 51 30); opaque = NO; layer = <CALayer: 0x75870b0>> | <UIImageView: 0x7588ed0; frame = (0 0; 51 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7588f30>> | <UIButtonLabel: 0x7587c50; frame = (14 7; 23 15); text = 'Edit'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7587d40>>
Tip
5
![Page 28: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/28.jpg)
Recursive descriptionXcode
<UINavigationItemView: 0x757be70; frame = (350 9; 68 27); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x757bf60>><UINavigationButton: 0x7586ed0; frame = (7 7; 51 30); opaque = NO; layer = <CALayer: 0x75870b0>> | <UIImageView: 0x7588ed0; frame = (0 0; 51 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7588f30>> | <UIButtonLabel: 0x7587c50; frame = (14 7; 23 15); text = 'Edit'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7587d40>>
Tip
5
![Page 29: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/29.jpg)
Language tipsObjective-C
![Page 30: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/30.jpg)
SubscriptingObjective-C Tip
6
![Page 31: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/31.jpg)
Subscripting
NSMutableArray *indexedValues = [NSMutableArray array];
Objective-C Tip
6
![Page 32: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/32.jpg)
Subscripting
NSMutableArray *indexedValues = [NSMutableArray array];indexedValues[0] = @"One";
Objective-C Tip
6
![Page 33: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/33.jpg)
Subscripting
NSMutableArray *indexedValues = [NSMutableArray array];indexedValues[0] = @"One";NSLog(@"value: %@", indexedValues[0]);
Objective-C Tip
6
![Page 34: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/34.jpg)
Subscripting
NSMutableArray *indexedValues = [NSMutableArray array];indexedValues[0] = @"One";NSLog(@"value: %@", indexedValues[0]);
Objective-C
NSMutableDictionary *keyedValues = [NSMutableDictionary dictionary];
Tip
6
![Page 35: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/35.jpg)
Subscripting
NSMutableArray *indexedValues = [NSMutableArray array];indexedValues[0] = @"One";NSLog(@"value: %@", indexedValues[0]);
Objective-C
NSMutableDictionary *keyedValues = [NSMutableDictionary dictionary];keyedValues[@"color"] = [UIColor blueColor];
Tip
6
![Page 36: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/36.jpg)
Subscripting
NSMutableArray *indexedValues = [NSMutableArray array];indexedValues[0] = @"One";NSLog(@"value: %@", indexedValues[0]);
Objective-C
NSMutableDictionary *keyedValues = [NSMutableDictionary dictionary];keyedValues[@"color"] = [UIColor blueColor];NSLog(@"value: %@", keyedValues[@"color"]);
Tip
6
![Page 37: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/37.jpg)
Custom-indexed subscriptingObjective-C Tip
6
![Page 38: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/38.jpg)
Custom-indexed subscripting
•Declaration
Objective-C Tip
6
![Page 39: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/39.jpg)
Custom-indexed subscripting
•Declaration@interface RecordSet : NSObject
Objective-C Tip
6
![Page 40: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/40.jpg)
Custom-indexed subscripting
•Declaration@interface RecordSet : NSObject@property (strong) NSMutableArray *indexedValues;
Objective-C Tip
6
![Page 41: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/41.jpg)
Custom-indexed subscripting
•Declaration@interface RecordSet : NSObject@property (strong) NSMutableArray *indexedValues;- (id)objectAtIndexedSubscript:(NSUInteger)idx;
Objective-C Tip
6
![Page 42: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/42.jpg)
Custom-indexed subscripting
•Declaration@interface RecordSet : NSObject@property (strong) NSMutableArray *indexedValues;- (id)objectAtIndexedSubscript:(NSUInteger)idx;- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;
Objective-C Tip
6
![Page 43: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/43.jpg)
Custom-indexed subscripting
•Declaration@interface RecordSet : NSObject@property (strong) NSMutableArray *indexedValues;- (id)objectAtIndexedSubscript:(NSUInteger)idx;- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;@end
Objective-C Tip
6
![Page 44: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/44.jpg)
Custom-indexed subscripting
•Declaration@interface RecordSet : NSObject@property (strong) NSMutableArray *indexedValues;- (id)objectAtIndexedSubscript:(NSUInteger)idx;- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;@end
Objective-C
• Implementation- (id)objectAtIndexedSubscript:(NSUInteger)idx { return [self.indexedValues objectAtIndex:idx];}
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx { [self.indexedValues insertObject:obj atIndex:idx];}
Tip
6
![Page 45: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/45.jpg)
Custom-indexed subscripting
•Declaration@interface RecordSet : NSObject@property (strong) NSMutableArray *indexedValues;- (id)objectAtIndexedSubscript:(NSUInteger)idx;- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;@end
Objective-C
• Implementation- (id)objectAtIndexedSubscript:(NSUInteger)idx { return [self.indexedValues objectAtIndex:idx];}
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx { [self.indexedValues insertObject:obj atIndex:idx];}
Tip
6
![Page 46: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/46.jpg)
Custom-indexed subscriptingObjective-C Tip
6
![Page 47: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/47.jpg)
Custom-indexed subscriptingObjective-C
• In use
Tip
6
![Page 48: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/48.jpg)
Custom-indexed subscriptingObjective-C
• In useRecordSet *recordSet = [[RecordSet alloc] init];
Tip
6
![Page 49: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/49.jpg)
Custom-indexed subscriptingObjective-C
• In useRecordSet *recordSet = [[RecordSet alloc] init];recordSet[0] = [Person personWithName:@"Ana"];
Tip
6
![Page 50: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/50.jpg)
Custom-indexed subscriptingObjective-C
• In useRecordSet *recordSet = [[RecordSet alloc] init];recordSet[0] = [Person personWithName:@"Ana"];recordSet[1] = [Person personWithName:@"Dave"];
Tip
6
![Page 51: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/51.jpg)
Custom-indexed subscriptingObjective-C
• In useRecordSet *recordSet = [[RecordSet alloc] init];recordSet[0] = [Person personWithName:@"Ana"];recordSet[1] = [Person personWithName:@"Dave"];view.person = recordSet[1];
Tip
6
![Page 52: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/52.jpg)
Custom-indexed subscriptingObjective-C
• In useRecordSet *recordSet = [[RecordSet alloc] init];recordSet[0] = [Person personWithName:@"Ana"];recordSet[1] = [Person personWithName:@"Dave"];view.person = recordSet[1];
Tip
6
![Page 53: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/53.jpg)
Custom-keyed subscriptingObjective-C Tip
6
![Page 54: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/54.jpg)
Custom-keyed subscriptingObjective-C
•Declaration
Tip
6
![Page 55: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/55.jpg)
Custom-keyed subscriptingObjective-C
•Declaration@interface Person : NSObject
Tip
6
![Page 56: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/56.jpg)
Custom-keyed subscriptingObjective-C
•Declaration@interface Person : NSObject@property (strong) NSMutableDictionary *keyedValues;
Tip
6
![Page 57: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/57.jpg)
Custom-keyed subscriptingObjective-C
•Declaration@interface Person : NSObject@property (strong) NSMutableDictionary *keyedValues;- (id)objectAtKeyedSubscript:(id <NSCopying>)key;
Tip
6
![Page 58: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/58.jpg)
Custom-keyed subscriptingObjective-C
•Declaration@interface Person : NSObject@property (strong) NSMutableDictionary *keyedValues;- (id)objectAtKeyedSubscript:(id <NSCopying>)key;- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;
Tip
6
![Page 59: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/59.jpg)
Custom-keyed subscriptingObjective-C
•Declaration@interface Person : NSObject@property (strong) NSMutableDictionary *keyedValues;- (id)objectAtKeyedSubscript:(id <NSCopying>)key;- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;@end
Tip
6
![Page 60: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/60.jpg)
Custom-keyed subscriptingObjective-C
•Declaration@interface Person : NSObject@property (strong) NSMutableDictionary *keyedValues;- (id)objectAtKeyedSubscript:(id <NSCopying>)key;- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;@end
Tip
6
![Page 61: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/61.jpg)
Custom-keyed subscriptingObjective-C
•Declaration@interface Person : NSObject@property (strong) NSMutableDictionary *keyedValues;- (id)objectAtKeyedSubscript:(id <NSCopying>)key;- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;@end
Tip
6
• Implementation- (id)objectAtKeyedSubscript:(id <NSCopying>)key { return [self.keyedValues objectForKey:key];}
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key { [self.keyedValues setObject:obj forKey:key];}
![Page 62: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/62.jpg)
Custom-keyed subscriptingObjective-C
•Declaration@interface Person : NSObject@property (strong) NSMutableDictionary *keyedValues;- (id)objectAtKeyedSubscript:(id <NSCopying>)key;- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;@end
Tip
6
• Implementation- (id)objectAtKeyedSubscript:(id <NSCopying>)key { return [self.keyedValues objectForKey:key];}
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key { [self.keyedValues setObject:obj forKey:key];}
![Page 63: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/63.jpg)
Custom-keyed subscriptingObjective-C
•Declaration@interface Person : NSObject@property (strong) NSMutableDictionary *keyedValues;- (id)objectAtKeyedSubscript:(id <NSCopying>)key;- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;@end
Tip
6
• Implementation- (id)objectAtKeyedSubscript:(id <NSCopying>)key { return [self.keyedValues objectForKey:key];}
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key { [self.keyedValues setObject:obj forKey:key];}
![Page 64: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/64.jpg)
Custom-keyed subscriptingObjective-C Tip
6
![Page 65: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/65.jpg)
Custom-keyed subscriptingObjective-C
• In use
Tip
6
![Page 66: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/66.jpg)
Custom-keyed subscriptingObjective-C
• In usePerson *person = [[Person alloc] init];
Tip
6
![Page 67: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/67.jpg)
Custom-keyed subscriptingObjective-C
• In usePerson *person = [[Person alloc] init];person[@"favoriteColor"] = [UIColor blueColor];
Tip
6
![Page 68: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/68.jpg)
Custom-keyed subscriptingObjective-C
• In usePerson *person = [[Person alloc] init];person[@"favoriteColor"] = [UIColor blueColor];view.backgroundColor = person[@"favoriteColor"];
Tip
6
![Page 69: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/69.jpg)
Custom-keyed subscriptingObjective-C
• In usePerson *person = [[Person alloc] init];person[@"favoriteColor"] = [UIColor blueColor];view.backgroundColor = person[@"favoriteColor"];
Tip
6
![Page 70: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/70.jpg)
Combined subscriptingObjective-C Tip
6
![Page 71: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/71.jpg)
Combined subscripting
•Declaration
Objective-C Tip
6
![Page 72: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/72.jpg)
Combined subscripting
•Declaration@interface UltraRecordSet : NSObject
Objective-C Tip
6
![Page 73: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/73.jpg)
Combined subscripting
•Declaration@interface UltraRecordSet : NSObject@property (strong) NSMutableArray *indexedValues;
Objective-C Tip
6
![Page 74: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/74.jpg)
Combined subscripting
•Declaration@interface UltraRecordSet : NSObject@property (strong) NSMutableArray *indexedValues;@property (strong) NSMutableDictionary *keyedValues;
Objective-C Tip
6
![Page 75: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/75.jpg)
Combined subscripting
•Declaration@interface UltraRecordSet : NSObject@property (strong) NSMutableArray *indexedValues;@property (strong) NSMutableDictionary *keyedValues;- (id)objectAtIndexedSubscript:(NSUInteger)idx;
Objective-C Tip
6
![Page 76: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/76.jpg)
Combined subscripting
•Declaration@interface UltraRecordSet : NSObject@property (strong) NSMutableArray *indexedValues;@property (strong) NSMutableDictionary *keyedValues;- (id)objectAtIndexedSubscript:(NSUInteger)idx;- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;
Objective-C Tip
6
![Page 77: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/77.jpg)
Combined subscripting
•Declaration@interface UltraRecordSet : NSObject@property (strong) NSMutableArray *indexedValues;@property (strong) NSMutableDictionary *keyedValues;- (id)objectAtIndexedSubscript:(NSUInteger)idx;- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;- (id)objectAtKeyedSubscript:(id <NSCopying>)key;
Objective-C Tip
6
![Page 78: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/78.jpg)
Combined subscripting
•Declaration@interface UltraRecordSet : NSObject@property (strong) NSMutableArray *indexedValues;@property (strong) NSMutableDictionary *keyedValues;- (id)objectAtIndexedSubscript:(NSUInteger)idx;- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;- (id)objectAtKeyedSubscript:(id <NSCopying>)key;- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;
Objective-C Tip
6
![Page 79: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/79.jpg)
Combined subscripting
•Declaration@interface UltraRecordSet : NSObject@property (strong) NSMutableArray *indexedValues;@property (strong) NSMutableDictionary *keyedValues;- (id)objectAtIndexedSubscript:(NSUInteger)idx;- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;- (id)objectAtKeyedSubscript:(id <NSCopying>)key;- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;@end
Objective-C Tip
6
![Page 80: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/80.jpg)
Combined subscripting
•Declaration@interface UltraRecordSet : NSObject@property (strong) NSMutableArray *indexedValues;@property (strong) NSMutableDictionary *keyedValues;- (id)objectAtIndexedSubscript:(NSUInteger)idx;- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;- (id)objectAtKeyedSubscript:(id <NSCopying>)key;- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;@end
Objective-C Tip
6
![Page 81: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/81.jpg)
Combined subscriptingObjective-C Tip
6
![Page 82: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/82.jpg)
Combined subscriptingObjective-C
• In use
Tip
6
![Page 83: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/83.jpg)
Combined subscriptingObjective-C
• In useUltraRecordSet *recordSet = [[UltraRecordSet alloc] init];
Tip
6
![Page 84: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/84.jpg)
Combined subscriptingObjective-C
• In useUltraRecordSet *recordSet = [[UltraRecordSet alloc] init];recordSet[@"cityName"] = @"Cupertino";
Tip
6
![Page 85: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/85.jpg)
Combined subscriptingObjective-C
• In useUltraRecordSet *recordSet = [[UltraRecordSet alloc] init];recordSet[@"cityName"] = @"Cupertino";recordSet[0] = [Person personWithName:@"Ana"];
Tip
6
![Page 86: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/86.jpg)
Combined subscriptingObjective-C
• In useUltraRecordSet *recordSet = [[UltraRecordSet alloc] init];recordSet[@"cityName"] = @"Cupertino";recordSet[0] = [Person personWithName:@"Ana"];recordSet[1] = [Person personWithName:@"Dave"];
Tip
6
![Page 87: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/87.jpg)
Combined subscriptingObjective-C
• In useUltraRecordSet *recordSet = [[UltraRecordSet alloc] init];recordSet[@"cityName"] = @"Cupertino";recordSet[0] = [Person personWithName:@"Ana"];recordSet[1] = [Person personWithName:@"Dave"];view.cityName = recordSet[@"cityName"];
Tip
6
![Page 88: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/88.jpg)
Combined subscriptingObjective-C
• In useUltraRecordSet *recordSet = [[UltraRecordSet alloc] init];recordSet[@"cityName"] = @"Cupertino";recordSet[0] = [Person personWithName:@"Ana"];recordSet[1] = [Person personWithName:@"Dave"];view.cityName = recordSet[@"cityName"];view.person = recordSet[1];
Tip
6
![Page 89: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/89.jpg)
Combined subscriptingObjective-C
• In useUltraRecordSet *recordSet = [[UltraRecordSet alloc] init];recordSet[@"cityName"] = @"Cupertino";recordSet[0] = [Person personWithName:@"Ana"];recordSet[1] = [Person personWithName:@"Dave"];view.cityName = recordSet[@"cityName"];view.person = recordSet[1];
Tip
6
![Page 90: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/90.jpg)
Reduce code noiseObjective-C
• Private declarations not necessary since Xcode 4.3@interface Example (PrivateMethods)- (NSString *)privateStatusStringForKey:(NSString *)key;@end
@implementation Example- (NSString *)currentStatusString {
return [self privateStatusStringForKey:self.currentKey];}
- (NSString *)privateStatusStringForKey:(NSString *)key { self.statusStringsByKey[key];
}@end
Tip
7
![Page 91: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/91.jpg)
Reduce code noiseObjective-C
• Private declarations not necessary since Xcode 4.3@interface Example (PrivateMethods)- (NSString *)privateStatusStringForKey:(NSString *)key;@end
@implementation Example- (NSString *)currentStatusString {
return [self privateStatusStringForKey:self.currentKey];}
- (NSString *)privateStatusStringForKey:(NSString *)key { self.statusStringsByKey[key];
}@end
Tip
7
![Page 92: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/92.jpg)
Reduce code noiseObjective-C
@implementation Example- (NSString *)currentStatusString {
return [self privateStatusStringForKey:self.currentKey];}
- (NSString *)privateStatusStringForKey:(NSString *)key { self.statusStringsByKey[key];
}@end
Tip
7
![Page 93: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/93.jpg)
Reduce code noiseObjective-C Tip
7
![Page 94: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/94.jpg)
Reduce code noiseObjective-C
• Synthesize not necessary for @property since Xcode 4.4@implementation Example@synthesize currentKey;@synthesize statusStringsByKey;
- (void)methodName { ...}
@end
Tip
7
![Page 95: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/95.jpg)
Reduce code noiseObjective-C
• Synthesize not necessary for @property since Xcode 4.4@implementation Example@synthesize currentKey;@synthesize statusStringsByKey;
- (void)methodName { ...}
@end
Tip
7
![Page 96: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/96.jpg)
Reduce code noiseObjective-C
• Synthesize not necessary for @property since Xcode 4.4@implementation Example- (void)methodName { ...}
@end
Tip
7
![Page 97: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/97.jpg)
DemoXcode
Mattt ThompsonNSHipster.com
![Page 98: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/98.jpg)
Data model tipsFoundation
Scott StevensonSoftware Engineer
![Page 99: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/99.jpg)
NSOperationFoundation Tip
8
![Page 100: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/100.jpg)
NSOperationFoundation
• Built on Grand Central Dispatch
Tip
8
![Page 101: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/101.jpg)
NSOperationFoundation
• Built on Grand Central Dispatch• Features
Tip
8
![Page 102: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/102.jpg)
NSOperationFoundation
• Built on Grand Central Dispatch• Features
■ Cancellation
Tip
8
![Page 103: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/103.jpg)
NSOperationFoundation
• Built on Grand Central Dispatch• Features
■ Cancellation■ Max count
Tip
8
![Page 104: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/104.jpg)
NSOperationFoundation
• Built on Grand Central Dispatch• Features
■ Cancellation■ Max count■ Dependencies
Tip
8
![Page 105: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/105.jpg)
NSOperationFoundation
• Built on Grand Central Dispatch• Features
■ Cancellation■ Max count■ Dependencies
•Objective-C API
Tip
8
![Page 106: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/106.jpg)
NSOperationFoundation
• Built on Grand Central Dispatch• Features
■ Cancellation■ Max count■ Dependencies
•Objective-C API■ Subclasses
Tip
8
![Page 107: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/107.jpg)
NSOperationFoundation
• Built on Grand Central Dispatch• Features
■ Cancellation■ Max count■ Dependencies
•Objective-C API■ Subclasses■ Categories
Tip
8
![Page 108: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/108.jpg)
NSOperationFoundation
• Built on Grand Central Dispatch• Features
■ Cancellation■ Max count■ Dependencies
•Objective-C API■ Subclasses■ Categories■ Key-Value Observing
Tip
8
![Page 109: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/109.jpg)
FoundationNSOperation
Tip
8
![Page 110: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/110.jpg)
NSOperation dependenciesFoundation Tip
8
![Page 111: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/111.jpg)
NSOperation dependenciesFoundation
- (void)addDependenciesForAuthorizedOperation:(WWDCOperation *)operation {
Tip
8
![Page 112: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/112.jpg)
NSOperation dependenciesFoundation
- (void)addDependenciesForAuthorizedOperation:(WWDCOperation *)operation {
Tip
8
self.authOperation = [[WWDCUserAuthorizationOperation alloc] init];
![Page 113: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/113.jpg)
NSOperation dependenciesFoundation
- (void)addDependenciesForAuthorizedOperation:(WWDCOperation *)operation {
Tip
8
self.authOperation = [[WWDCUserAuthorizationOperation alloc] init];[operation addDependency:self.authOperation];
![Page 114: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/114.jpg)
NSOperation dependenciesFoundation
- (void)addDependenciesForAuthorizedOperation:(WWDCOperation *)operation {
Tip
8
self.authOperation = [[WWDCUserAuthorizationOperation alloc] init];[operation addDependency:self.authOperation];[self.queue addOperation: self.authOperation waitUntilFinished:NO];
![Page 115: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/115.jpg)
NSOperation dependenciesFoundation
- (void)addDependenciesForAuthorizedOperation:(WWDCOperation *)operation {
Tip
8
self.authOperation = [[WWDCUserAuthorizationOperation alloc] init];[operation addDependency:self.authOperation];[self.queue addOperation: self.authOperation waitUntilFinished:NO];
}
![Page 116: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/116.jpg)
NSOperation dependenciesFoundation
- (void)addDependenciesForAuthorizedOperation:(WWDCOperation *)operation {
Tip
8
self.authOperation = [[WWDCUserAuthorizationOperation alloc] init];[operation addDependency:self.authOperation];[self.queue addOperation: self.authOperation waitUntilFinished:NO];
}
- (void)setFavorite:(BOOL)status forSessionID:(NSString *)sessionIDcompletion:(void(^)(BOOL))block {
![Page 117: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/117.jpg)
NSOperation dependenciesFoundation
- (void)addDependenciesForAuthorizedOperation:(WWDCOperation *)operation {
Tip
8
self.authOperation = [[WWDCUserAuthorizationOperation alloc] init];[operation addDependency:self.authOperation];[self.queue addOperation: self.authOperation waitUntilFinished:NO];
}
- (void)setFavorite:(BOOL)status forSessionID:(NSString *)sessionIDcompletion:(void(^)(BOOL))block {
WWDCSetFavoriteOperation *operation;
![Page 118: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/118.jpg)
NSOperation dependenciesFoundation
- (void)addDependenciesForAuthorizedOperation:(WWDCOperation *)operation {
Tip
8
self.authOperation = [[WWDCUserAuthorizationOperation alloc] init];[operation addDependency:self.authOperation];[self.queue addOperation: self.authOperation waitUntilFinished:NO];
}
- (void)setFavorite:(BOOL)status forSessionID:(NSString *)sessionIDcompletion:(void(^)(BOOL))block {
WWDCSetFavoriteOperation *operation;operation =[[WWDCSetFavoriteOperation alloc] initWithSuccessBlock:block];
![Page 119: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/119.jpg)
NSOperation dependenciesFoundation
- (void)addDependenciesForAuthorizedOperation:(WWDCOperation *)operation {
Tip
8
self.authOperation = [[WWDCUserAuthorizationOperation alloc] init];[operation addDependency:self.authOperation];[self.queue addOperation: self.authOperation waitUntilFinished:NO];
}
- (void)setFavorite:(BOOL)status forSessionID:(NSString *)sessionIDcompletion:(void(^)(BOOL))block {
WWDCSetFavoriteOperation *operation;operation =[[WWDCSetFavoriteOperation alloc] initWithSuccessBlock:block];operation.favorite = status;
![Page 120: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/120.jpg)
NSOperation dependenciesFoundation
- (void)addDependenciesForAuthorizedOperation:(WWDCOperation *)operation {
Tip
8
self.authOperation = [[WWDCUserAuthorizationOperation alloc] init];[operation addDependency:self.authOperation];[self.queue addOperation: self.authOperation waitUntilFinished:NO];
}
- (void)setFavorite:(BOOL)status forSessionID:(NSString *)sessionIDcompletion:(void(^)(BOOL))block {
WWDCSetFavoriteOperation *operation;operation =[[WWDCSetFavoriteOperation alloc] initWithSuccessBlock:block];operation.favorite = status;[self addDependenciesForAuthorizedOperation:operation];
![Page 121: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/121.jpg)
NSOperation dependenciesFoundation
- (void)addDependenciesForAuthorizedOperation:(WWDCOperation *)operation {
Tip
8
self.authOperation = [[WWDCUserAuthorizationOperation alloc] init];[operation addDependency:self.authOperation];[self.queue addOperation: self.authOperation waitUntilFinished:NO];
}
- (void)setFavorite:(BOOL)status forSessionID:(NSString *)sessionIDcompletion:(void(^)(BOOL))block {
WWDCSetFavoriteOperation *operation;operation =[[WWDCSetFavoriteOperation alloc] initWithSuccessBlock:block];operation.favorite = status;[self addDependenciesForAuthorizedOperation:operation];[self.operationQueue addOperation:operation];
![Page 122: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/122.jpg)
NSOperation dependenciesFoundation
- (void)addDependenciesForAuthorizedOperation:(WWDCOperation *)operation {
Tip
8
self.authOperation = [[WWDCUserAuthorizationOperation alloc] init];[operation addDependency:self.authOperation];[self.queue addOperation: self.authOperation waitUntilFinished:NO];
}
- (void)setFavorite:(BOOL)status forSessionID:(NSString *)sessionIDcompletion:(void(^)(BOOL))block {
WWDCSetFavoriteOperation *operation;operation =[[WWDCSetFavoriteOperation alloc] initWithSuccessBlock:block];operation.favorite = status;[self addDependenciesForAuthorizedOperation:operation];[self.operationQueue addOperation:operation];
}
![Page 123: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/123.jpg)
NSExpressionFoundation Tip
9
![Page 124: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/124.jpg)
NSExpressionFoundation
• Stand back, I'm going to try math
Tip
9
![Page 125: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/125.jpg)
NSExpressionFoundation
• Stand back, I'm going to try mathNSString *text = @"3 + 5 * 4e10";
Tip
9
![Page 126: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/126.jpg)
NSExpressionFoundation
• Stand back, I'm going to try mathNSString *text = @"3 + 5 * 4e10";NSExpression *e = [NSExpression expressionWithFormat:text, nil];
Tip
9
![Page 127: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/127.jpg)
NSExpressionFoundation
• Stand back, I'm going to try mathNSString *text = @"3 + 5 * 4e10";NSExpression *e = [NSExpression expressionWithFormat:text, nil];NSNumber *result = [e expressionValueWithObject:nil context:nil];
Tip
9
![Page 128: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/128.jpg)
NSExpressionFoundation
• Stand back, I'm going to try mathNSString *text = @"3 + 5 * 4e10";NSExpression *e = [NSExpression expressionWithFormat:text, nil];NSNumber *result = [e expressionValueWithObject:nil context:nil];NSLog(@"result: %@", result);
Tip
9
![Page 129: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/129.jpg)
NSExpressionFoundation
• Stand back, I'm going to try mathNSString *text = @"3 + 5 * 4e10";NSExpression *e = [NSExpression expressionWithFormat:text, nil];NSNumber *result = [e expressionValueWithObject:nil context:nil];NSLog(@"result: %@", result);
Tip
9
result: 200000000003
![Page 130: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/130.jpg)
NSSet and NSOrderedSetFoundation
•Guaranteed uniqueness, fast membership lookup•Membership cache• Set calculations
Tip
10
![Page 131: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/131.jpg)
NSSet and NSOrderedSetFoundation
•Guaranteed uniqueness, fast membership lookup•Membership cache• Set calculations
Tip
10
-intersectsSet: == YES
![Page 132: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/132.jpg)
NSSet and NSOrderedSetFoundation
•Guaranteed uniqueness, fast membership lookup•Membership cache• Set calculations
Tip
10
-intersectsSet: == YES -isSubsetOfSet: == YES
![Page 133: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/133.jpg)
NSSet and NSOrderedSetFoundation
•Guaranteed uniqueness•Membership cache• Set calculations
Tip
10
![Page 134: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/134.jpg)
NSSet and NSOrderedSetFoundation
•Guaranteed uniqueness•Membership cache• Set calculations
Tip
10
-minusSet:
![Page 135: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/135.jpg)
NSSet and NSOrderedSetFoundation
•Guaranteed uniqueness•Membership cache• Set calculations
Tip
10
-minusSet: -unionSet:
![Page 136: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/136.jpg)
NSSet and NSOrderedSetFoundation
•Guaranteed uniqueness•Membership cache• Set calculations
Tip
10
![Page 137: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/137.jpg)
NSSet and NSOrderedSetFoundation
•Guaranteed uniqueness•Membership cache• Set calculations
Tip
10
Designing Code for Performance Nob HillFriday 9:00AM
![Page 138: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/138.jpg)
Collection tricksFoundation Tip
11
![Page 139: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/139.jpg)
Collection tricksFoundation
• Reverse arrays quickly inlineNSArray *numbers = @[ @1, @2, @3 ];NSArray *reversed = numbers.reverseObjectEnumerator.allObjects;
Tip
11
![Page 140: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/140.jpg)
Collection tricksFoundation
• Reverse arrays quickly inlineNSArray *numbers = @[ @1, @2, @3 ];NSArray *reversed = numbers.reverseObjectEnumerator.allObjects;
•Guarantee a mutable objectNSArray *unknown = self.values; // may be nilNSMutableArray *newArray = [NSMutableArray arrayWithArray:unknown];
Tip
11
![Page 141: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/141.jpg)
Collection tricksFoundation
• Reverse arrays quickly inlineNSArray *numbers = @[ @1, @2, @3 ];NSArray *reversed = numbers.reverseObjectEnumerator.allObjects;
•Guarantee a mutable objectNSArray *unknown = self.values; // may be nilNSMutableArray *newArray = [NSMutableArray arrayWithArray:unknown];
•Declare and enumerate different collection typesid<NSFastEnumeration> collection = values;for (id object in collection) {
... }
Tip
11
![Page 142: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/142.jpg)
Foundation
@implementation Manager
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(__unsafe_unretained id [])buffer count:(NSUInteger)len {
return [self.subordinates countByEnumeratingWithState:state objects:buffer count:len];}
@end
NSFastEnumeration to your class
![Page 143: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/143.jpg)
Data model tipsFoundation and Core Foundation
Mattt ThompsonNSHipster.com
![Page 144: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/144.jpg)
NSValue
• Scalars• Structs
■ Ranges■ Points, sizes, and rects
•Unretained references
![Page 145: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/145.jpg)
NSValue Tip
12
![Page 146: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/146.jpg)
NSValue
NSMutableArray *array = [@[] mutableCopy];array[0] = [NSValue valueWithPoint:CGPointZero];array[1] = [NSValue valueWithRange:NSMakeRange(3, 17)];
Tip
12
![Page 147: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/147.jpg)
NSValue
NSMutableArray *array = [@[] mutableCopy];array[0] = [NSValue valueWithPoint:CGPointZero];array[1] = [NSValue valueWithRange:NSMakeRange(3, 17)];
typedef struct RGB {float red, green, blue;
} _RGB;
Tip
12
![Page 148: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/148.jpg)
NSValue
NSMutableArray *array = [@[] mutableCopy];array[0] = [NSValue valueWithPoint:CGPointZero];array[1] = [NSValue valueWithRange:NSMakeRange(3, 17)];
typedef struct RGB {float red, green, blue;
} _RGB;
RGB color = {1.0f, 0.0f, 0.0f};
Tip
12
![Page 149: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/149.jpg)
NSValue
NSMutableArray *array = [@[] mutableCopy];array[0] = [NSValue valueWithPoint:CGPointZero];array[1] = [NSValue valueWithRange:NSMakeRange(3, 17)];
typedef struct RGB {float red, green, blue;
} _RGB;
RGB color = {1.0f, 0.0f, 0.0f};array[2] = [NSValue valueWithBytes:&color objCType:@encode(RGB)];
Tip
12
![Page 150: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/150.jpg)
NSValue
• object conforms to <NSCopying>NSMutableDictionary *dictionary = [@{} mutableCopy];dictionary[object] = @42;
• object does not conform to <NSCopying>NSMutableDictionary *dictionary = [@{} mutableCopy];dictionary[[NSValue valueWithNonretainedObject:object]] = @42;
Tip
12
![Page 151: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/151.jpg)
Key-Value Coding
[employee valueForKey:@"name"];employee.name;
[employee valueForKeyPath:@"manager.name"];employee.manager.name;
Tip
13
![Page 152: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/152.jpg)
Key-Value Coding Tip
13
![Page 153: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/153.jpg)
Key-Value Coding
NSArray *words = @[@"Alpha", @"Bravo", @"Charlie"];
Tip
13
![Page 154: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/154.jpg)
Key-Value Coding
NSArray *words = @[@"Alpha", @"Bravo", @"Charlie"];
[words valueForKey:@"uppercaseString"];// @[@"ALPHA", @"BRAVO", @"CHARLIE"]
Tip
13
![Page 155: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/155.jpg)
Key-Value Coding
NSArray *words = @[@"Alpha", @"Bravo", @"Charlie"];
[words valueForKey:@"uppercaseString"];// @[@"ALPHA", @"BRAVO", @"CHARLIE"]
[words valueForKey:@"length"]; // @[@5, @5, @7]
Tip
13
![Page 156: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/156.jpg)
Key-Value Coding
- (NSDictionary *)dictionaryWithValuesForKeys:(NSArray *)keys; NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; for (NSString *key in keys) { dictionary[key] = [myObject valueForKey:key]; }}
- (void)setValuesForKeysWithDictionary:(NSDictionary *)keyedValues; for (NSString *key in dictionary.allKeys) { id value = dictionary[key]; [myObject setValue:value forKey:key];}
Tip
13
![Page 157: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/157.jpg)
KVC Collection Operators
[employee valueForKeyPath:@"colleagues.@count"];
[staff valueForKeyPath:@"@avg.salary"];
[week valueForKeyPath:@"@max.temperature"];
Tip
14
![Page 158: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/158.jpg)
KVC Collection Operators
• Simple collection operators•Object operators•Array and set operators
![Page 160: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/160.jpg)
Simple Collection Operators
![Page 161: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/161.jpg)
Simple Collection Operators
@count NSNumber
![Page 162: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/162.jpg)
Simple Collection Operators
@count NSNumber
@sum NSNumber
@avg NSNumber
![Page 163: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/163.jpg)
Simple Collection Operators
@count NSNumber
@sum NSNumber
@avg NSNumber
@max id
@min id
![Page 164: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/164.jpg)
Object Operators
@unionOfObjects NSArray
@distinctUnionOfObjects NSArray
![Page 165: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/165.jpg)
KVC Collection Operators
•Remove duplicate values in array without NSSet[array valueForKeyPath:@"@distinctUnionOfObjects.self"]
Tip
14
![Page 166: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/166.jpg)
Array and Set Operators
@unionOfArrays NSArray or NSSet
@distinctUnionOfArrays NSArray or NSSet
@distinctUnionOfSets NSArray or NSSet
Tip
14
![Page 167: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/167.jpg)
Array and Set Operators Tip
14
![Page 168: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/168.jpg)
Array and Set Operators
@unionOfArrays
Tip
14
![Page 169: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/169.jpg)
Array and Set Operators
@distinctUnionOfArrays
Tip
14
![Page 170: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/170.jpg)
NSDataDetector
![Page 171: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/171.jpg)
NSDataDetector
![Page 172: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/172.jpg)
NSDataDetector
![Page 173: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/173.jpg)
NSDataDetector
•Dates•Addresses• Links• Phone numbers• Transit information
![Page 174: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/174.jpg)
NSDataDetector Tip
15
![Page 175: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/175.jpg)
NSDataDetector
NSString *string = @"123 Main St. / (555) 555-5555";
Tip
15
![Page 176: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/176.jpg)
NSDataDetector
NSString *string = @"123 Main St. / (555) 555-5555";
NSError *error;
Tip
15
![Page 177: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/177.jpg)
NSDataDetector
NSString *string = @"123 Main St. / (555) 555-5555";
NSError *error;NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink | NSTextCheckingTypePhoneNumber error:&error];
Tip
15
![Page 178: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/178.jpg)
NSDataDetector
NSString *string = @"123 Main St. / (555) 555-5555";
NSError *error;NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink | NSTextCheckingTypePhoneNumber error:&error];
[detector enumerateMatchesInString:string options:kNilOptions range:NSMakeRange(0, [string length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) { NSLog(@"Match: %@", result);
}];
Tip
15
![Page 179: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/179.jpg)
CFStringTransform
![Page 180: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/180.jpg)
CFStringTransform
• Strip accents and diacritics
![Page 181: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/181.jpg)
CFStringTransform
• Strip accents and diacritics•Name Unicode characters
![Page 182: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/182.jpg)
CFStringTransform
• Strip accents and diacritics•Name Unicode characters• Encode XML hex entities
![Page 183: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/183.jpg)
CFStringTransform
• Strip accents and diacritics•Name Unicode characters• Encode XML hex entities• Transliterate between writing systems
![Page 184: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/184.jpg)
Boolean CFStringTransform (CFMutableStringRef string,CFRange *range,CFStringRef transform,Boolean reverse
);
CFStringTransform
![Page 185: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/185.jpg)
Strip Accents and Diacritics
Énġlišh låcks iñterêsţing diaçrïtičş
![Page 186: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/186.jpg)
Strip Accents and Diacritics
English lacks interesting diacritics
![Page 187: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/187.jpg)
NSMutableString *string = [@"Énġlišh låcks iñterêsţing diaçrïtičş" mutableCopy];
CFStringTransform((__bridge CFMutableStringRef)(string), NULL, kCFStringTransformStripCombiningMarks, NO);
Strip Accents and Diacritics Tip
16
![Page 188: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/188.jpg)
Name Unicode Characters
![Page 189: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/189.jpg)
Name Unicode Characters
Character Name
A LATIN CAPITAL LETTER A
Å LATIN CAPITAL LETTER A WITH RING ABOVE
☃ SNOWMAN
![Page 190: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/190.jpg)
Name Unicode Characters
Character Name
A LATIN CAPITAL LETTER A
Å LATIN CAPITAL LETTER A WITH RING ABOVE
☃ SNOWMAN
![Page 191: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/191.jpg)
Name Unicode Characters
Character Name
A LATIN CAPITAL LETTER A
Å LATIN CAPITAL LETTER A WITH RING ABOVE
☃ SNOWMAN
![Page 192: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/192.jpg)
Name Unicode Characters
Character Name
A LATIN CAPITAL LETTER A
Å LATIN CAPITAL LETTER A WITH RING ABOVE
☃ SNOWMAN
![Page 193: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/193.jpg)
Name Unicode Characters
![Page 194: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/194.jpg)
Name Unicode Characters
NSMutableString *string = [@"🐷 " mutableCopy];
CFStringTransform((__bridge CFMutableStringRef)(string), NULL, kCFStringTransformToUnicodeName, NO);
Tip
17
![Page 195: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/195.jpg)
Name Unicode Characters
@"PIG FACE"
Tip
17
![Page 196: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/196.jpg)
Transliterate Between Orthographies
안녕하세요
![Page 197: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/197.jpg)
Transliterate Between Orthographies
NSMutableString *string = [@"오빤 강남스타일" mutableCopy];CFStringTransform((__bridge CFMutableStringRef)(string), NULL, kCFStringTransformToLatin, NO);
Tip
18
![Page 198: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/198.jpg)
annyeonghaseyo
Transliterate Between Orthographies
![Page 199: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/199.jpg)
Transliteration | Transformations
![Page 200: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/200.jpg)
Transliteration | Transformations
привет
γειά σου 안녕שלום
สวัสดี中文
![Page 201: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/201.jpg)
Transliteration | Transformations
![Page 202: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/202.jpg)
mrḥbạprivet
geiá sou
annyeong
şlwm
s wạs dī
zhōng wén
Transliteration | Transformations
![Page 203: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/203.jpg)
ひらがな カタカナ
Transliteration | Transformations
![Page 204: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/204.jpg)
ヒラガナ かたかな
Transliteration | Transformations
![Page 205: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/205.jpg)
hiragana katakana
Transliteration | Transformations
![Page 206: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/206.jpg)
“On OS X v10.4 and later, with CFStringTransform you can also use
any valid ICU transform ID defined in the ICU User Guide for Transforms.”
Apple Developer Documentation
![Page 207: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/207.jpg)
Transliteration | Transformations
![Page 208: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/208.jpg)
!"#$%&!#'"
Բարև Ձեզহ"ােলা
హ"gɹiːtɪŋs
नम#$
!"ોTransliteration | Transformations
![Page 209: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/209.jpg)
Normalizing Input
hello! こんにちは! สวัสดี! !"#$%! 您好!
![Page 210: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/210.jpg)
Normalizing Input Tip
19
![Page 211: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/211.jpg)
Normalizing Input
CFMutableStringRef string; string = (__bridge CFMutableStringRef)[@"Hello! こんにちは! สวัสดี! مرحبا! 您好!" mutableCopy];
Tip
19
![Page 212: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/212.jpg)
Normalizing Input
// Hello! kon'nichiha! swạsdī! mrḥbạ! nín hǎo!
CFMutableStringRef string; string = (__bridge CFMutableStringRef)[@"Hello! こんにちは! สวัสดี! مرحبا! 您好!" mutableCopy];
Tip
19
![Page 213: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/213.jpg)
Normalizing Input
// Hello! kon'nichiha! swạsdī! mrḥbạ! nín hǎo!CFStringTransform(string, NULL, kCFStringTransformToLatin, NO);
CFMutableStringRef string; string = (__bridge CFMutableStringRef)[@"Hello! こんにちは! สวัสดี! مرحبا! 您好!" mutableCopy];
Tip
19
![Page 214: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/214.jpg)
Normalizing Input
// Hello! kon'nichiha! swạsdī! mrḥbạ! nín hǎo!CFStringTransform(string, NULL, kCFStringTransformToLatin, NO);
CFMutableStringRef string; string = (__bridge CFMutableStringRef)[@"Hello! こんにちは! สวัสดี! مرحبا! 您好!" mutableCopy];
// Hello! kon'nichiha! swasdi! mrhba! nin hao!
Tip
19
![Page 215: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/215.jpg)
Normalizing Input
// Hello! kon'nichiha! swạsdī! mrḥbạ! nín hǎo!CFStringTransform(string, NULL, kCFStringTransformToLatin, NO);
CFMutableStringRef string; string = (__bridge CFMutableStringRef)[@"Hello! こんにちは! สวัสดี! مرحبا! 您好!" mutableCopy];
// Hello! kon'nichiha! swasdi! mrhba! nin hao!CFStringTransform(string, NULL, kCFStringTransformStripCombiningMarks, NO);
Tip
19
![Page 216: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/216.jpg)
Normalizing Input
// Hello! kon'nichiha! swạsdī! mrḥbạ! nín hǎo!CFStringTransform(string, NULL, kCFStringTransformToLatin, NO);
CFMutableStringRef string; string = (__bridge CFMutableStringRef)[@"Hello! こんにちは! สวัสดี! مرحبا! 您好!" mutableCopy];
// Hello! kon'nichiha! swasdi! mrhba! nin hao!CFStringTransform(string, NULL, kCFStringTransformStripCombiningMarks, NO);
// hello! kon'nichiha! swasdi! mrhba! nin hao!
Tip
19
![Page 217: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/217.jpg)
Normalizing Input
// Hello! kon'nichiha! swạsdī! mrḥbạ! nín hǎo!CFStringTransform(string, NULL, kCFStringTransformToLatin, NO);
CFMutableStringRef string; string = (__bridge CFMutableStringRef)[@"Hello! こんにちは! สวัสดี! مرحبا! 您好!" mutableCopy];
// Hello! kon'nichiha! swasdi! mrhba! nin hao!CFStringTransform(string, NULL, kCFStringTransformStripCombiningMarks, NO);
// hello! kon'nichiha! swasdi! mrhba! nin hao!CFStringLowercase(string, NULL);
Tip
19
![Page 218: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/218.jpg)
Normalizing Input Tip
19
![Page 219: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/219.jpg)
Normalizing Input
NSMutableArray *mutableWords = [NSMutableArray array];
Tip
19
![Page 220: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/220.jpg)
Normalizing Input
NSMutableArray *mutableWords = [NSMutableArray array];[string enumerateLinguisticTagsInRange:NSMakeRange(0, string.length)
Tip
19
![Page 221: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/221.jpg)
Normalizing Input
NSMutableArray *mutableWords = [NSMutableArray array];[string enumerateLinguisticTagsInRange:NSMakeRange(0, string.length)
scheme:NSLinguisticTagSchemeTokenType
Tip
19
![Page 222: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/222.jpg)
Normalizing Input
NSMutableArray *mutableWords = [NSMutableArray array];[string enumerateLinguisticTagsInRange:NSMakeRange(0, string.length)
scheme:NSLinguisticTagSchemeTokenType options:kNilOptions
Tip
19
![Page 223: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/223.jpg)
Normalizing Input
NSMutableArray *mutableWords = [NSMutableArray array];[string enumerateLinguisticTagsInRange:NSMakeRange(0, string.length)
scheme:NSLinguisticTagSchemeTokenType options:kNilOptions orthography:nil
Tip
19
![Page 224: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/224.jpg)
Normalizing Input
NSMutableArray *mutableWords = [NSMutableArray array];[string enumerateLinguisticTagsInRange:NSMakeRange(0, string.length)
scheme:NSLinguisticTagSchemeTokenType options:kNilOptions orthography:nil usingBlock:
^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) {
if ([tag isEqualToString:NSLinguisticTagWord]) { [mutableWords addObject:[string substringWithRange:tokenRange]]; }}];
Tip
19
![Page 225: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/225.jpg)
Normalizing Input
hello! こんにちは! สวัสดี! !"#$%! 您好!
![Page 226: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/226.jpg)
Normalizing Input
hello! こんにちは! สวัสดี! !"#$%! 您好! hello, kon'nichiha, swasdi, mrhba, nin, hao
![Page 227: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/227.jpg)
Animation tipsCore Animation
Scott StevensonSoftware Engineer
![Page 228: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/228.jpg)
![Page 229: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/229.jpg)
Core Animation
UIKit
Core Animation
OpenGL ES
Core OS
AppKit
iOS OS X
Core Animation
OpenGL
Core OS
![Page 230: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/230.jpg)
UIView / NSView
CALayer
Core Animation
CAAnimation @"color"
CAAnimation @"position"
Time
![Page 231: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/231.jpg)
Core AnimationCAGradientLayer
Tip
20
![Page 232: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/232.jpg)
CAGradientLayerCore Animation
CAGradientLayer *gradient = [CAGradientLayer layer];gradient.frame = CGRectMake(150, 250, 500, 500);
UIColor *c1 = [UIColor colorWithRed:0.09 green:0.70 blue:0.98 alpha:1.0];UIColor *c2 = [UIColor colorWithRed:0.07 green:0.41 blue:0.95 alpha:1.0];UIColor *c3 = [UIColor colorWithRed:0.81 green:0.46 blue:0.93 alpha:1.0];gradient.colors = @[(id)c2.CGColor, (id)c3.CGColor, (id)c3.CGColor];
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"colors"];anim.toValue = @[(id)c1.CGColor, (id)c2.CGColor, (id)c2.CGColor];anim.duration = 4.0;anim.autoreverses = YES;anim.repeatCount = 1e100;[gradient addAnimation:anim forKey:@"colors"];
[self.view.layer addSublayer:gradient];
Tip
20
![Page 233: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/233.jpg)
CAGradientLayerCore Animation
CAGradientLayer *gradient = [CAGradientLayer layer];gradient.frame = CGRectMake(150, 250, 500, 500);
UIColor *c1 = [UIColor colorWithRed:0.09 green:0.70 blue:0.98 alpha:1.0];UIColor *c2 = [UIColor colorWithRed:0.07 green:0.41 blue:0.95 alpha:1.0];UIColor *c3 = [UIColor colorWithRed:0.81 green:0.46 blue:0.93 alpha:1.0];gradient.colors = @[(id)c2.CGColor, (id)c3.CGColor, (id)c3.CGColor];
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"colors"];anim.toValue = @[(id)c1.CGColor, (id)c2.CGColor, (id)c2.CGColor];anim.duration = 4.0;anim.autoreverses = YES;anim.repeatCount = 1e100;[gradient addAnimation:anim forKey:@"colors"];
[self.view.layer addSublayer:gradient];
Tip
20
![Page 234: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/234.jpg)
CAGradientLayerCore Animation
CAGradientLayer *gradient = [CAGradientLayer layer];gradient.frame = CGRectMake(150, 250, 500, 500);
UIColor *c1 = [UIColor colorWithRed:0.09 green:0.70 blue:0.98 alpha:1.0];UIColor *c2 = [UIColor colorWithRed:0.07 green:0.41 blue:0.95 alpha:1.0];UIColor *c3 = [UIColor colorWithRed:0.81 green:0.46 blue:0.93 alpha:1.0];gradient.colors = @[(id)c2.CGColor, (id)c3.CGColor, (id)c3.CGColor];
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"colors"];anim.toValue = @[(id)c1.CGColor, (id)c2.CGColor, (id)c2.CGColor];anim.duration = 4.0;anim.autoreverses = YES;anim.repeatCount = 1e100;[gradient addAnimation:anim forKey:@"colors"];
[self.view.layer addSublayer:gradient];
Tip
20
![Page 235: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/235.jpg)
CAGradientLayerCore Animation
CAGradientLayer *gradient = [CAGradientLayer layer];gradient.frame = CGRectMake(150, 250, 500, 500);
UIColor *c1 = [UIColor colorWithRed:0.09 green:0.70 blue:0.98 alpha:1.0];UIColor *c2 = [UIColor colorWithRed:0.07 green:0.41 blue:0.95 alpha:1.0];UIColor *c3 = [UIColor colorWithRed:0.81 green:0.46 blue:0.93 alpha:1.0];gradient.colors = @[(id)c2.CGColor, (id)c3.CGColor, (id)c3.CGColor];
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"colors"];anim.toValue = @[(id)c1.CGColor, (id)c2.CGColor, (id)c2.CGColor];anim.duration = 4.0;anim.autoreverses = YES;anim.repeatCount = 1e100;[gradient addAnimation:anim forKey:@"colors"];
[self.view.layer addSublayer:gradient];
Tip
20
![Page 236: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/236.jpg)
CAGradientLayerCore Animation
CAGradientLayer *gradient = [CAGradientLayer layer];gradient.frame = CGRectMake(150, 250, 500, 500);
UIColor *c1 = [UIColor colorWithRed:0.09 green:0.70 blue:0.98 alpha:1.0];UIColor *c2 = [UIColor colorWithRed:0.07 green:0.41 blue:0.95 alpha:1.0];UIColor *c3 = [UIColor colorWithRed:0.81 green:0.46 blue:0.93 alpha:1.0];gradient.colors = @[(id)c2.CGColor, (id)c3.CGColor, (id)c3.CGColor];
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"colors"];anim.toValue = @[(id)c1.CGColor, (id)c2.CGColor, (id)c2.CGColor];anim.duration = 4.0;anim.autoreverses = YES;anim.repeatCount = 1e100;[gradient addAnimation:anim forKey:@"colors"];
[self.view.layer addSublayer:gradient];
Tip
20
![Page 237: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/237.jpg)
Core AnimationCAGradientLayer
Tip
20
![Page 238: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/238.jpg)
Core AnimationCAShapeLayer
Tip
21
![Page 239: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/239.jpg)
CAShapeLayerCore Animation Tip
21
CAShapeLayer *shapeLayer = [CAShapeLayer layer];shapeLayer.frame = CGRectMake(150, 250, 500, 500);
UIBezierPath* path1 = [UIBezierPath bezierPath];// ... add points to shapeshapeLayer.path = path1.CGPath;
UIBezierPath* path2 = [UIBezierPath bezierPath];// ... add points to shape
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"path"];anim.toValue = (id)path2.CGPath;anim.duration = 4.0;anim.autoreverses = YES;anim.repeatCount = 1e100;[gradient addAnimation:anim forKey:@"path"];
[self.view.layer addSublayer:gradient];
![Page 240: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/240.jpg)
CAShapeLayerCore Animation Tip
21
CAShapeLayer *shapeLayer = [CAShapeLayer layer];shapeLayer.frame = CGRectMake(150, 250, 500, 500);
UIBezierPath* path1 = [UIBezierPath bezierPath];// ... add points to shapeshapeLayer.path = path1.CGPath;
UIBezierPath* path2 = [UIBezierPath bezierPath];// ... add points to shape
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"path"];anim.toValue = (id)path2.CGPath;anim.duration = 4.0;anim.autoreverses = YES;anim.repeatCount = 1e100;[gradient addAnimation:anim forKey:@"path"];
[self.view.layer addSublayer:gradient];
![Page 241: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/241.jpg)
CAShapeLayerCore Animation Tip
21
CAShapeLayer *shapeLayer = [CAShapeLayer layer];shapeLayer.frame = CGRectMake(150, 250, 500, 500);
UIBezierPath* path1 = [UIBezierPath bezierPath];// ... add points to shapeshapeLayer.path = path1.CGPath;
UIBezierPath* path2 = [UIBezierPath bezierPath];// ... add points to shape
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"path"];anim.toValue = (id)path2.CGPath;anim.duration = 4.0;anim.autoreverses = YES;anim.repeatCount = 1e100;[gradient addAnimation:anim forKey:@"path"];
[self.view.layer addSublayer:gradient];
![Page 242: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/242.jpg)
CAShapeLayerCore Animation Tip
21
CAShapeLayer *shapeLayer = [CAShapeLayer layer];shapeLayer.frame = CGRectMake(150, 250, 500, 500);
UIBezierPath* path1 = [UIBezierPath bezierPath];// ... add points to shapeshapeLayer.path = path1.CGPath;
UIBezierPath* path2 = [UIBezierPath bezierPath];// ... add points to shape
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"path"];anim.toValue = (id)path2.CGPath;anim.duration = 4.0;anim.autoreverses = YES;anim.repeatCount = 1e100;[gradient addAnimation:anim forKey:@"path"];
[self.view.layer addSublayer:gradient];
![Page 243: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/243.jpg)
CAShapeLayerCore Animation Tip
21
CAShapeLayer *shapeLayer = [CAShapeLayer layer];shapeLayer.frame = CGRectMake(150, 250, 500, 500);
UIBezierPath* path1 = [UIBezierPath bezierPath];// ... add points to shapeshapeLayer.path = path1.CGPath;
UIBezierPath* path2 = [UIBezierPath bezierPath];// ... add points to shape
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"path"];anim.toValue = (id)path2.CGPath;anim.duration = 4.0;anim.autoreverses = YES;anim.repeatCount = 1e100;[gradient addAnimation:anim forKey:@"path"];
[self.view.layer addSublayer:gradient];
![Page 244: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/244.jpg)
CAShapeLayerCore Animation Tip
21
CAShapeLayer *shapeLayer = [CAShapeLayer layer];shapeLayer.frame = CGRectMake(150, 250, 500, 500);
UIBezierPath* path1 = [UIBezierPath bezierPath];// ... add points to shapeshapeLayer.path = path1.CGPath;
UIBezierPath* path2 = [UIBezierPath bezierPath];// ... add points to shape
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"path"];anim.toValue = (id)path2.CGPath;anim.duration = 4.0;anim.autoreverses = YES;anim.repeatCount = 1e100;[gradient addAnimation:anim forKey:@"path"];
[self.view.layer addSublayer:gradient];
![Page 245: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/245.jpg)
Core AnimationCAShapeLayer
Tip
21
![Page 246: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/246.jpg)
Core AnimationCAShapeLayer + CAGradientLayer = ?
Tip
22
![Page 247: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/247.jpg)
Core AnimationCAShapeLayer + CAGradientLayer = ?
Tip
22
![Page 248: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/248.jpg)
Core AnimationCAShapeLayer + CAGradientLayer = ?
Tip
22
self.gradientLayer.mask = shapeLayer;
![Page 249: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/249.jpg)
Tip
22Interactive animationCore Animation
![Page 250: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/250.jpg)
Tip
22CAMediaTiming for interactive animationsCore Animation
#import "MyViewController.h"#import <QuartzCore/QuartzCore.h>
@interface MyViewController ()
@property (nonatomic, weak) IBOutlet UIView *squareContainer;@property (nonatomic, weak) IBOutlet UIView *square;@property (nonatomic, weak) IBOutlet UISlider *slider;
@end
![Page 251: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/251.jpg)
Tip
22CAMediaTiming for interactive animationsCore Animation
- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.square.layer.speed = 0;
CGRect rect = self.squareContainer.bounds; rect.size.height = CGRectGetMinY(self.slider.frame); CGFloat dx = CGRectGetWidth(self.square.frame)/2.0; CGFloat dy = CGRectGetHeight(self.square.frame)/2.0; CGRect r = CGRectInset(rect, dx, dy); CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; animation.path = [[UIBezierPath bezierPathWithOvalInRect:r] CGPath]; animation.calculationMode = kCAAnimationPaced; animation.speed = 0.25; [self.square.layer addAnimation:animation forKey:@"position"];}
![Page 252: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/252.jpg)
Tip
22CAMediaTiming for interactive animationsCore Animation
- (IBAction)sliderChanged:(id)sender { self.square.layer.timeOffset = self.slider.value;}
![Page 253: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/253.jpg)
Tip
22Interactive animationCore Animation
![Page 254: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/254.jpg)
Performance tipsCore Data
![Page 255: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/255.jpg)
![Page 256: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/256.jpg)
Core Data
NSManagedContext
NSManagedObject
NSManagedObject
NSManagedObject
NSFetchRequest
NSManagedObject
NSManagedObject
NSManagedObject
NSPersistentStore
NSPersistentStoreCoordinator
![Page 257: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/257.jpg)
NSPrivateQueueConcurrencyTypeCore Data
Main Queue
Private Queue
-performBlock:
Tip
23
Your App
Main Context Worker Context
![Page 258: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/258.jpg)
Private QueueCore Data
NSManagedObjectContext *bgContext;bgContext = [[NSManagedObjectContext alloc] initWithConcurrencyType: NSPrivateQueueConcurrencyType];
[context performBlock:^{ // (add, remove, change objects.) saveCompleted = [context save:& saveError];}];
Tip
23
![Page 259: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/259.jpg)
Really fast fetchesCore Data
•Only specific propertiesNSFetchRequestfetch.propertiesToFetch = @[@"name", @"phone"];
•Only the raw valuesfetch.resultType = NSDictionaryResultType
•Only the object idfetch.resultType = NSManagedObjectIDResultType
•Only the countfetch.resultType = NSCountResultType
Tip
24
![Page 260: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/260.jpg)
Really fast fetchesCore Data
•Work in groups of objectsNSFetchRequestfetch.fetchBatchSize = 100;
• Reduce cross-entity fetchesfetch.relationshipKeyPathsForPrefetching = @[ @"artist", @"catalog" ];
Tip
25
![Page 261: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/261.jpg)
Really fast fetchesCore Data
•Work in groups of objectsNSFetchRequestfetch.fetchBatchSize = 100;
• Reduce cross-entity fetchesfetch.relationshipKeyPathsForPrefetching = @[ @"artist", @"catalog" ];
Tip
25
Core Data Performance Optimization and Debugging Nob HillWednesday 2:00PM
![Page 262: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/262.jpg)
Core Data
NSPersistentStore
NSIncrementalStore
NSIncrementalStore
Custom Store Type
Tip
26
![Page 263: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/263.jpg)
Implementation tipsUIKit
![Page 264: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/264.jpg)
UICollectionViewUIKit Tip
27
![Page 265: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/265.jpg)
UICollectionViewUIKit Tip
27
![Page 266: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/266.jpg)
UICollectionViewUIKit
•Grid views, custom layouts• Similar to UITableView
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)cv { return self.collectionViewSections.count;}
- (NSInteger)collectionView:(UICollectionView *)cv numberOfItemsInSection:(NSInteger)section { return [[self sessionsInSection:section] count];}
Tip
27
![Page 267: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/267.jpg)
UICollectionViewUIKit Tip
27
![Page 268: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/268.jpg)
UICollectionViewUIKit
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)path { NSArray *sessions = [self sessionsInSection:path.section]; WWDCSession* session = sessions[indexPath.item];
WWDCiPadScheduleSessionView *cell = nil; cell = [cv dequeueReusableCellWithReuseIdentifier:@"sessionView" forIndexPath:path]; [cell setSession:session]; return cell;}
Tip
27
![Page 269: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/269.jpg)
Modern improvementsAppKit
![Page 270: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/270.jpg)
View-based NSTableViewAppKit Tip
28
![Page 271: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/271.jpg)
View-based NSTableViewAppKit
• Similar to UITableView•Hardware accelerated•Arbitrary views, no NSCell subclassing!• Layout in IB•Animation
NSTableViewAnimationEffectFadeNSTableViewAnimationEffectGapNSTableViewAnimationSlideUpNSTableViewAnimationSlideDownNSTableViewAnimationSlideLeftNSTableViewAnimationSlideRight
Tip
28
![Page 272: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/272.jpg)
View-based tablesAppKit
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { return self.objects.count;}
- (NSTableRowView *)tableView:(NSTableView *)table rowViewForRow:(NSInteger)row { MyRowView *rowView; rowView = [table makeViewWithIdentifier:@"RowView" owner:self]; return rowView;}
Tip
29
![Page 273: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/273.jpg)
View-based tablesAppKit
- (NSView *)tableView:(NSTableView *)table viewForTableColumn:(NSTableColumn *)col row:(NSInteger)row {
NSTableCellView *cellView = nil; id objectForRow = self.objects[row]; BOOL isSelected = (row == self.selectedRow);
if ([self tableView:table isGroupRow:row]) { cellView = [table makeViewWithIdentifier:@"GroupView" owner:self]; cellView.textField.stringValue = [object title]; cellView.textField.textColor = (isSelected) ? [NSColor blueColor]; return cellView; } else { ...
Tip
29
![Page 274: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/274.jpg)
View-based tablesAppKit
if ([self tableView:table isGroupRow:row]) { cellView = [table makeViewWithIdentifier:@"GroupView" owner:self]; cellView.textField.stringValue = [object title]; cellView.textField.textColor = (isSelected) ? [NSColor blueColor]; return cellView;} else { MyGridView *gridView = [table makeViewWithIdentifier:@"Grid" owner:self]; gridView.dataSource = self.gridDataSource; gridView.delegate = self; return gridView;}
Tip
29
![Page 275: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/275.jpg)
More Information
Dave DeLongApp Frameworks and Developer Tools [email protected]
Apple Developer Documentationhttp://developer.apple.com/documentation
Apple Developer Forumshttp://devforums.apple.com
![Page 276: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/276.jpg)
Related Sessions
Designing Code for Performance Nob HillFriday 9:00AM
Core Data Performance Optimization and Debugging Nob HillWednesday 2:00PM
![Page 277: Hidden Gems in Cocoa and Cocoa Touch - Apple Inc. · Hidden Gems in Cocoa and Cocoa Touch Scott Stevenson Software Engineer. Mattt Thompson NSHipster.com. Xcode Core Data UIKit AppKit](https://reader033.vdocuments.net/reader033/viewer/2022042606/5f85ee64f816c727992fa33b/html5/thumbnails/277.jpg)