• 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: [super initialize]?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [super initialize]?


  • Subject: Re: [super initialize]?
  • From: Jim Correia <email@hidden>
  • Date: Fri, 2 Sep 2005 22:20:01 -0400

On Sep 2, 2005, at 7:36 PM, mmalcolm crawford wrote:

If, however, you add a dependent key, 'weeklyCost', to the Employee class, and implement its initializer:

+ (void)initialize {
[self setKeys:[NSArray arrayWithObjects:@"hourlyWage", @"hoursPerWeek", nil]
triggerChangeNotificationsForDependentKey:@"weeklyCost"];
}


then KVO notifications are not sent for 'fullName' for instances of Employee.

What is your recommended solution to this problem? This feels like a common enough thing to want to do that the framework should provide a mechanism (which is why I filed an enhancement request.)


Absent such mechanism my approach was to have all my managed objects inherit from MyManagedObject which does something like this:

@implementation MyManagedObject

- (id)initWithEntity:(NSEntityDescription *)entity insertIntoManagedObjectContext:(NSManagedObjectContext *)context
{
// lazy register dependent keys - see header documentation for why it is done this way
[[self class] registerDependentKeysIfNecessary];


return [super initWithEntity: entity insertIntoManagedObjectContext: context];
}


+ (void)registerDependentKeys
{
// no dependent keys to register in the base class, subclasses must message super
}


+ (void)registerDependentKeysIfNecessary
{
    static    NSMutableDictionary        *processedClasses = nil;

    if (processedClasses == nil)
        processedClasses = [[NSMutableDictionary alloc] init];

    NSString    *classname = NSStringFromClass([self class]);

    if (nil == [processedClasses objectForKey: classname])
    {
        [self registerDependentKeys];
        [processedClasses setObject: classname forKey: classname];
    }
}

@end

- Jim


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: [super initialize]?
      • From: mmalcolm crawford <email@hidden>
References: 
 >[super initialize]? (From: "Christopher Hickman" <email@hidden>)
 >Re: [super initialize]? (From: Scott Anguish <email@hidden>)
 >Re: [super initialize]? (From: Jim Correia <email@hidden>)
 >Re: [super initialize]? (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: NSString initWithBytes
  • Next by Date: Re: Is this a bug in NSCalendarDate?
  • Previous by thread: Re: [super initialize]?
  • Next by thread: Re: [super initialize]?
  • Index(es):
    • Date
    • Thread