On Mon, Aug 24, 2009 at 6:19 PM, Michael A.
Crawford<[email protected]> wrote:
> Why would the class initializer be called more than once when my app starts
> up? Is this expected behavior?  In case you're wondering, it is called
> twice.
>
> + (void)initialize
> {
>    // Create the defaults dictionary, fill it with the standard values,
>    // and register it.
>    NSMutableDictionary* defaultValues = [NSMutableDictionary dictionary];
>
>    [defaultValues setObject:[NSNumber numberWithBool:YES]
>                      forKey:CDFilterKey];
>    [defaultValues setObject:[NSNumber numberWithBool:YES]
>                      forKey:CDNotifyUserOnAnalysisCompletionKey];
>    [defaultValues setObject:[NSNumber numberWithBool:YES]
>                      forKey:CDPlaylistReminderKey];
>
>    [[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
>
>    MCLog(@"Registered defaults: %@", defaultValues);
> }
>


You should generally check for "self == [MyClass class]" at the start
of +[MyClass initialize].  It can get called twice if, say, someone
subclasses your class, and the subclass doesn't implement initialize.
_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to