• 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: Ryan Dingman <email@hidden>
  • Date: Thu, 3 Apr 2003 20:25:52 -0800

Vince and Jane,

I don't think that this is a bug in key/value coding, but rather a bug in Jane's code; more specifically, a problem with the configuration of the NSTableView. Key/value coding does provide type coercion between scalars and objects. For BOOL, key/value coding will convert to/from an NSNumber. I think that your problem likely is due to the fact that when you edit the value via a field in NSTableView that NSTableView is setting an NSString on your value and hence the exception that you get. Try applying an NSNumberFormatter to the column in which you are editing your BOOL value in the NSTableView. The NSNumberFormatter will convert the NSString to an NSNumber before it gets sent through key/value coding to get set on you object.

I hope this helps.

ryan

On Thursday, April 3, 2003, at 09:46 AM, Vince DeMarco wrote:

*This message was transferred with a trial version of CommuniGate(tm) Pro*
On Thursday, April 3, 2003, at 8:16 AM, Jane wrote:

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:

AppController.h
@interface AppController : NSObject {
IBOutlet NSTableView *tableView;
NSMutableArray *aMutableArray;
}
@end

AppController.m
#import "AppController.h"
#import "TestObject.h"
@implementation AppController
-(void)awakeFromNib {
aMutableArray = [[NSMutableArray
arrayWithObject:[[TestObject alloc] init]] retain];
[tableView setDataSource:self];
[[[tableView tableColumns] objectAtIndex:0] setIdentifier:@"aBool"]; }
-(int)numberOfRowsInTableView:(NSTableView *)aTableView {
return [aMutableArray count]; }
-(id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {
return [[aMutableArray objectAtIndex:rowIndex]
valueForKey:[aTableColumn identifier]]; }
-(void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {
[[aMutableArray objectAtIndex:rowIndex] takeValue:anObject
forKey:[aTableColumn identifier]]; }
@end

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

AnObject.m
#import "TestObject.h"
@implementation TestObject
-(id)init {
if (self = [super init]) aBool = YES;
return self;
}
-(void)setABool:(BOOL)yesNo { aBool = yesNo; }
-(BOOL)aBool { return aBool; }
@end

IB was used to add one NSTableView with one column to the main window.

The initial value of aBool displays in the table correctly as "1". But when the cell is selected, a value of 0 is typed, and ENTER pressed, the following error displays on the console:

2003-04-02 09:03:59.908 TakeValueError[576] *** -[NSCFString charValue]: selector not recognized
2003-04-02 09:03:59.915 TakeValueError[576] Exception raised during posting of notification. Ignored. exception: *** -[NSCFString charValue]: selector not recognized

Is this a known problem or should I use Apple's error submission process to notify Apple?

We did discover the following workaround:

- (void)setABool:(int)yesNo { aBool = yesNo; }


I think its a bug, please file one.

vince
_______________________________________________
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.
_______________________________________________
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.

  • Follow-Ups:
    • Re: takeValue:forKey and BOOL
      • From: Jane <email@hidden>
References: 
 >Re: takeValue:forKey and BOOL (From: Vince DeMarco <email@hidden>)

  • Prev by Date: Re: nscolorwell cell question
  • Next by Date: Re: Inspector-aware undo in Doc-based app
  • Previous by thread: Re: takeValue:forKey and BOOL
  • Next by thread: Re: takeValue:forKey and BOOL
  • Index(es):
    • Date
    • Thread