Created
September 5, 2012 17:24
-
-
Save jeremy-w/3640491 to your computer and use it in GitHub Desktop.
ABPerson and bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2012-09-05 13:23:50.803 bind-abperson[53387:707] dudeView name: DUDE! | |
2012-09-05 13:23:50.804 bind-abperson[53387:707] dudeView name: Duuuuuuuude | |
2012-09-05 13:23:50.805 bind-abperson[53387:707] dudeView.name binding: { | |
NSObservedKeyPath = name; | |
NSObservedObject = "<Dude: 0x7f9ce3c15ac0>"; | |
NSOptions = { | |
NSMultipleValuesPlaceholder = "<null>"; | |
NSNoSelectionPlaceholder = "<null>"; | |
NSNotApplicablePlaceholder = "<null>"; | |
NSNullPlaceholder = "<null>"; | |
NSRaisesForNotApplicableKeys = 1; | |
NSValueTransformer = "<null>"; | |
NSValueTransformerName = "<null>"; | |
}; | |
} | |
2012-09-05 13:23:50.894 bind-abperson[53387:707] personView name: (null) | |
2012-09-05 13:23:50.896 bind-abperson[53387:707] personView name: (null) | |
2012-09-05 13:23:50.899 bind-abperson[53387:707] personView.name binding: { | |
NSObservedKeyPath = name; | |
NSObservedObject = "ABPerson (0x7f9ce483a920) {\n\tABPersonFlags : 0\n\tCreation : 2012-09-05 17:23:50 +0000\n\tFirst : <REAL name>\n\tModification : 2012-09-05 17:23:50 +0000\n\tPrivate : <ABCDContact 0x7f9ce3c78fc0>\n\tStore : ~/Library/Application Support/AddressBook/AddressBook-v22.abcddb\n\tUnique ID : 010F0C0F-B710-4BCE-AB88-F1405DE281AB:ABPerson\n}"; | |
NSOptions = { | |
NSMultipleValuesPlaceholder = "<null>"; | |
NSNoSelectionPlaceholder = "<null>"; | |
NSNotApplicablePlaceholder = "<null>"; | |
NSNullPlaceholder = "<null>"; | |
NSRaisesForNotApplicableKeys = 1; | |
NSValueTransformer = "<null>"; | |
NSValueTransformerName = "<null>"; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clang -fobjc-arc -framework Cocoa -framework AddressBook bind-abperson.m -o bind-abperson | |
#import <Cocoa/Cocoa.h> | |
#import <AddressBook/AddressBook.h> | |
@interface ABPerson (LikeARealCocoaObject) | |
@property(strong, nonatomic) NSString *name; | |
@end | |
@implementation ABPerson (LikeARealCocoaObject) | |
- (NSString *)name | |
{ | |
return [self valueForProperty:kABFirstNameProperty]; | |
} | |
- (void)setName:(NSString *)name | |
{ | |
[self setValue:name forProperty:kABFirstNameProperty]; | |
} | |
@end | |
@interface View : NSObject | |
@property(strong, nonatomic) NSString *name; | |
@end | |
@implementation View @end | |
@interface Dude : NSObject | |
@property(strong, nonatomic) NSString *name; | |
@end | |
@implementation Dude @end | |
int | |
main(void) | |
{ | |
@autoreleasepool { | |
View *dudeView = [[View alloc] init]; | |
Dude *dude = [[Dude alloc] init]; | |
[dude setName:@"DUDE!"]; | |
[dudeView bind:@"name" toObject:dude withKeyPath:@"name" options:nil]; | |
NSLog(@"dudeView name: %@", dudeView.name); | |
[dude setName:@"Duuuuuuuude"]; | |
NSLog(@"dudeView name: %@", dudeView.name); | |
NSLog(@"dudeView.name binding: %@", [dudeView infoForBinding:@"name"]); | |
View *personView = [[View alloc] init]; | |
ABPerson *p = [[ABPerson alloc] init]; | |
[p setValue:@"<NAME>" forProperty:kABFirstNameProperty]; | |
[personView bind:@"name" toObject:p withKeyPath:@"name" options:nil]; | |
NSLog(@"personView name: %@", personView.name); | |
[p setName:@"<REAL name>"]; | |
NSLog(@"personView name: %@", personView.name); | |
NSLog(@"personView.name binding: %@", | |
[personView infoForBinding:@"name"]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment