Re: takeValue:forKey and BOOL
Re: takeValue:forKey and BOOL
- Subject: Re: takeValue:forKey and BOOL
- From: Jérôme Laurens <email@hidden>
- Date: Fri, 4 Apr 2003 12:50:30 +0200
Le vendredi, 4 avr 2003, ` 12:23 Europe/Zurich, Jane a icrit :
Thank you for responding to my message. Two things, the documentation
for NSKeyValueCoding states "Scalar values (such as int or float) can
be accessed as well. Their values are just passed using NSNumber
objects, instead. The key-value coding methods automatically detect
the scalar instance variables and convert them to and from NSNumber
objects as needed."
This means that if you code
@interface MyObject: NSObject
{
BOOL aBool;
}
then
[MyObject takeValue: [NSNumber numberWithBool: flag] forKey: @"aBool"];
is equivalent to
MyObject-> bool = flag;
or
[MyObject setABool: flag];
if you have an accessor
and conversely
[[MyObject valueForKey: @"aBool"] boolValue];
will return MyObject-> aBool or [MyObject aBool]
Moreover, in your code previous code
-(void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {
[[aMutableArray objectAtIndex:rowIndex] takeValue:anObject
forKey:[aTableColumn identifier]]; }
you are not sure that anObject is a NSNumber. So in your setter
-(void)setABool: (id) argument, you will have to implement your own
filter anObject->bool.
I just see Ryan Dingman post: this is another solution as well. In any
case you have to write the anObject->bool filter somewhere either in
the -(void)setABool: (id) argument or in a number formatter.
_______________________________________________
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.