• 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: subclass of NSManagedObject not behaving as expected
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: subclass of NSManagedObject not behaving as expected


  • Subject: Re: subclass of NSManagedObject not behaving as expected
  • From: Chris Hanson <email@hidden>
  • Date: Sat, 21 Apr 2007 22:15:57 -0700

On Apr 20, 2007, at 7:39 PM, Gonzalo Castro wrote:

My EmployeeMO.m subclass contains the methods found here:

http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/Concepts/DependentKeys.html

That's probably the problem. You need to write accessor methods for properties that are managed by Core Data -- that is, specified in your model -- differently than those for regular NSObject subclasses.


http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html

In this case, the accessors for your "firstName" property would look like this:

  - (NSString *)firstName {
      [self willAccessValueForKey:@"firstName"];
      NSString *value = [self primitiveValueForKey:@"firstName"];
      [self didAccessValueForKey:@"firstName"];
      return value;
  }

  - (void)setFirstName:(NSString *)value {
      [self willChangeValueForKey:@"firstName"];
      NSString *temp = [value copy];
      [self setPrimitiveValue:temp forKey:@"firstName"];
      [temp release];
      [self didChangeValueForKey:@"firstName"];
  }

If you change your accessors for your "firstName" and "lastName" properties to look like this, you should be fine. Your "fullName" property -- since it's not declared in your model -- doesn't need these kinds of changes, it can just use [self firstName] and [self lastName] as it undoubtedly does already.

  -- Chris

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: 
 >subclass of NSManagedObject not behaving as expected (From: Gonzalo Castro <email@hidden>)

  • Prev by Date: Re: Customize NSAlert?
  • Next by Date: Re: NSSound + NSBundle
  • Previous by thread: subclass of NSManagedObject not behaving as expected
  • Next by thread: Getting default system font
  • Index(es):
    • Date
    • Thread