Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom Bindings clarification



On Jan 27, 2004, at 8:36 AM, mmalcolm crawford wrote:

If you just want to establish a binding, you can do it programatically:
[textField bind: @"backgroundColor" toObject: $sourceObject
withKeyPath: $backgroundTextColorKey options:nil];

In the case of a colour binding, "of course", you'll also have to specify at least one binding option -- to use NSUnarchiveFromData (since you can't store colours directly in Preferences).

You might therefore end up with code that looks something like this:

NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];

[bindingOptions setObject:NSUnarchiveFromDataTransformerName forKey:@"NSValueTransformerName"];
// other options

[textField bind: @"backgroundColor"
toObject: [NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.backgroundTextColor"
options:bindingOptions];


I've put a complete example at:
<http://homepage.mac.com/mmalc/CocoaExamples/ ManualBindingsColourPreference.zip>

mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Custom Bindings clarification (From: Peer Allan <email@hidden>)
 >Re: Custom Bindings clarification (From: mmalcolm crawford <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.