n00b cocoa bindings question
n00b cocoa bindings question
- Subject: n00b cocoa bindings question
- From: Luke Evans <email@hidden>
- Date: Mon, 07 May 2007 16:50:54 -0700
- Thread-topic: n00b cocoa bindings question
Hello cocoa-dev people,
My initial foray into bindings has been to 'listen' to configuration
parameter changes. In doing so, I bumped into a problem I find interesting
and haven't been able to find comment on in the docs.
On initialisation of my document class, I execute a routine that attempts to
bind to preferences. Specifically, I have a piece of code that attempts to
bind the 'local' (i.e. self) method "bufferKeys" to a value managed by the
user defaults controller:
// ... snip
// "Buffer key presses" boolean preference
[self bind:@"bufferKeys"
toObject:userDefCtrl
withKeyPath:@"values.keyboardBuffering"
options:[NSDictionary dictionaryWithObject:[NSNumber
numberWithBool:YES] forKey:@"NSContinuouslyUpdatesValue"]
];
// ... snip
Now, after a bunch of head scratching at the somewhat opaque runtime error:
... *** -[NSCFString charValue]: selector not recognized [self = 0x1e3d8]
...I hypothesised that my problem might lie with the 'bufferKeys' accessor
methods on 'self'. The intention is that the 'bufferKeys' property is a
BOOL, ergo I had accessors that looked like this:
- (BOOL)bufferKeys {
return _bufferKeys;
}
- (void)setBufferKeys:(BOOL)buffer {
_bufferKeys = buffer;
}
I considered what the difference would be between this and the other
bindings (to strings and integers) which work just fine - but surmised that
it must simply be that BOOLs are handled differently, or not at all
(presumably requiring transformation)... though this is a little surprising.
My unsatisfying fix (for now) is to replace these two accessor methods with:
- (int)bufferKeys {
return _bufferKeys;
}
- (void)setBufferKeys:(int)buffer {
_bufferKeys = (buffer != 0);
}
... whereupon everything is peachy.
So, I suppose my questions are rather straightforward:
1. Have I missed something in the docs?
2. Is it true that BOOL needs a different treatment (than say, 'int') in
setting up the binding?
3. What is the canonical way of dealing with this, assuming that it's not
unreasonable for me to be trying to bind to a boolean property?
I'm still getting used to the cocoa late binding stuff, and I suppose am
wishing that the dev tools supported higher-level views of the runtime
messages - though I've read there are are some verbosity flags one can set
to get extra diagnostic tracing, at least. Anyway, that's an aside, and
perhaps becomes less important as you develop your 'spidey sense' for the
cocoa world.
Cheers
Luke
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden