Re: setting a BOOL var in a NSManagedObject
Re: setting a BOOL var in a NSManagedObject
- Subject: Re: setting a BOOL var in a NSManagedObject
- From: Jim Correia <email@hidden>
- Date: Wed, 2 Jan 2008 11:16:16 -0500
On Jan 2, 2008, at 11:05 AM, Steven Crosley wrote:
I have a subclass of a NSManagedObject where one of the attributes
is a Boolean type. My method to set the value of this attribute
looks like this:
- (void)setActive:(BOOL)flag
{
[self willChangeValueForKey:@"active"];
[self setPrimitiveValue:flag forKey:@"active"];
[self didChangeValueForKey:@"active"];
}
However, I'm getting the warning message below:
warning: passing argument 1 of 'setPrimitiveValue:forKey:' makes
pointer from integer without a cast
The compiler warning is telling you what you've done wrong.
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath;
-setValue:forKey: accepts an object as the value. A BOOL is not an
object. If you want to write your KVC compliant accessors in terms of
BOOL, you'll need to box the BOOL in an NSNumber to use it with -
setValue:forKey:.
Using the data modeler's "Copy Method Implementations to Clipboard"
is also a good way to start. (But be sure you understand why it
generated the code that it did.)
Jim
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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