Re: n00b cocoa bindings question
Re: n00b cocoa bindings question
- Subject: Re: n00b cocoa bindings question
- From: Luke Evans <email@hidden>
- Date: Wed, 09 May 2007 13:07:43 -0700
- Thread-topic: n00b cocoa bindings question
Thanks Jonathon, that was helpful.
At least, it has already highlighted a possible misunderstanding I had
that defaults were always represented as strings in essence, even if
manually coerced into other things. I¹ll try expressing my defaults as the
types I¹m actually interested in, and see if this makes a difference.
Assuming that solves my immediate issue, it still leaves with with the
following thoughts:
1. I need to defend against the fact that somebody could change the
persisted default to a type that would cause this problem (i.e. back to a
string, as in this case).
2. ... and I¹m still left wondering a bit why automatic coercion works to
integers from a string, but doesn¹t go the seemingly small extra¹ step to
be capable of producing a boolean (especially given the C¹ style
representation/interpretation of boolean (true if any non-zero value).
On 5/9/07 6:44 AM, "Jonathon Mah" <email@hidden> wrote:
> Hi Luke,
>
> On 2007-05-08, at 09:20, Luke Evans wrote:
>
>> > // "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]
>
> That exception shows that the the user defaults controller is reading
> the keyboardBuffering value as a string, and trying to convert it
> into a boolean (by calling -charValue, which is implementation speak
> for calling -boolValue). When you changed your methods to take an
> int, everything is fine because NSString does respond to -intValue.
>
> I don't know why it would be reading the value as a string. Perhaps
> you are registering default defaults and supplying it with a string,
> or perhaps you managed to get a string stored in your preferences
> file. Maybe it has even changed itself to an NSNumber by now (by your
> usage of an int).
>
> If all else fails, you can use [[NSUserDefaults standardUserDefaults]
> boolForKey:@"keyboardBuffering"], and register to receive the
> NSUserDefaultsDidChangeNotification.
>
>
>
> Jonathon Mah
> email@hidden
>
>
_______________________________________________
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