• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: takeValue:forKey and BOOL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: takeValue:forKey and BOOL


  • Subject: Re: takeValue:forKey and BOOL
  • From: Jane <email@hidden>
  • Date: Fri, 4 Apr 2003 03:26:56 -0700

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." I expect the BOOL to be detected as well and converted from an NSNumber via boolValue. I did implement your suggestion, however, to see if it would work and received the following error message:

2003-04-04 02:51:34.320 TakeValueError[425] *** -[NSCFString boolValue]: selector not recognized
2003-04-04 02:51:34.334 TakeValueError[425] Exception raised during posting of notification. Ignored. exception: *** -[NSCFString boolValue]: selector not recognized

I also see a complication with changing the accessor method to using an NSNumber. For example, say I want to set the BOOL instance variable from the state of a control, such as

[testObject setABool:[aButton state]]

I would have to wrap [aButton state] in an NSNumber.

On Thursday, April 3, 2003, at 10:08 AM, Jirtme Laurens wrote:


Le jeudi, 3 avr 2003, ` 18:16 Europe/Zurich, Jane a icrit :

We have found what appears to be an error in takeValue:forKey when the instance variable in the target object is a BOOL. The following code illustrates problem:

I am afraid this bug is yours: the cocoa doc says

- (void)takeValue:(id)value forKey:(NSString *)key
- (id)valueForKey:(NSString *)key

so you cannot use a BOOL, you must wrap the flag in a NSNumber, use instead

TestObject.h
@interface TestObject : NSObject {
BOOL aBool;
}
-(void)setABool:(NSNumber *)yesNo;
-(NSNumber *)aBool;
@end

AnObject.m
#import "TestObject.h"
@implementation TestObject
-(void)setABool:(NSNumber *)yesNo { aBool = [yesNo boolValue]; }
-(NSNumber *)aBool { return [NSNumber numberWithBool: aBool]; }
@end
_______________________________________________
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.

  • Prev by Date: Deselect TextFields
  • Next by Date: Re: Deselect TextFields
  • Previous by thread: Re: takeValue:forKey and BOOL
  • Next by thread: Re: takeValue:forKey and BOOL
  • Index(es):
    • Date
    • Thread