• 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: setting a BOOL var in a NSManagedObject
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >setting a BOOL var in a NSManagedObject (From: Steven Crosley <email@hidden>)

  • Prev by Date: Re: setting a BOOL var in a NSManagedObject
  • Next by Date: Re: Scripting Bridge && filteredArrayUsingPredicate
  • Previous by thread: Re: setting a BOOL var in a NSManagedObject
  • Next by thread: NSCollectionView coding headstart extra steps
  • Index(es):
    • Date
    • Thread