Re: Building a dynamic class factory ( +load init order)
Re: Building a dynamic class factory ( +load init order)
- Subject: Re: Building a dynamic class factory ( +load init order)
- From: "Ken Ferry" <email@hidden>
- Date: Fri, 28 Dec 2007 18:27:03 -0500
Hi Thomas,
Whatever the problem is, I don't think it's in the info you posted
(which doesn't look like real code).
The docs on +load are too paranoid, and are due to be revised. As of
Leopard, you can count on all +load methods in frameworks you link to
be called before any +load method in your code. So, what you've posted
looks okay modulo typos. Though, the autoreleased dictionary would
leak and spew a log to the console due to there being no autorelease
pool in place at this point.
The message to TELibraryFactory is safe in that the class object will
exist at this point, but if the class has a +load method, it may not
have run yet. TELibraryFactory's +load will run before that of any of
its subclasses, though.
Ken
Cocoa Frameworks
On Dec 28, 2007 2:54 PM, Thomas Engelmeier <email@hidden> wrote:
> Hi,
>
> I have some old code from the Tiger aera that fails on Leopard.
> Basically some classes call
>
> + (void) load
> {
> NSDictionary *aDictionary = [aDictionary dictionaryWithObjectsAndKeys:
> [self class], @"class",
> @"plugin name", @"name",
> nil]];
> [TELibraryFactory registerClass:aDictionary];
> }
>
> with a implementation like
>
> + (void) registerClass:(NSDictionary *) aClass
> {
> if( !sRegisteredClasses )
> sRegisteredClasses = [[NSMutableArray alloc] init];
> [sRegisteredClasses addObject:aClass];
> }
>
> Seems I relied too much that the Foundation classes are already loaded
> and initialized when +load is called - now the dictionary creation
> already crashes.
> Is there any better way to prevent I have to add
>
>
> [[TELibraryFactory register:[TESubclass1 description]];
> [[TELibraryFactory register:[TESubclass2 description]];
> // ...
> [[TELibraryFactory register:[TESubclassN description]];
>
> manually in a separate file and keep that in sync each time a new
> class is added?
>
> _______________________________________________
>
> 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
>
_______________________________________________
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