Re: Initialization order
Re: Initialization order
- Subject: Re: Initialization order
- From: "Clark S. Cox III" <email@hidden>
- Date: Fri, 9 May 2003 15:49:11 -0400
On Friday, May 9, 2003, at 16:17 US/Eastern, Mark Levin wrote:
Is there any way to control or determine the order in which
+initialize is called for classes?
Yes, the order is well defined. When any method is called on a
particular class that hasn't yet had +initialize called, +initialize
is called.
For example:
@interface MyClass : NSObject {}
@end
@implementation MyClass
+(void)initialize
{
NSString *temp = [NSString stringWithUTF8String: "Blah"];
}
@end
int main()
{
[[NSObject alloc] init];
/*
[NSObject initialize] is called right before [NSObject alloc];
*/
[[NSMutableArray alloc] init];
/*
Directly before [NSMutableArray alloc] is called, [NSArray
initialize] is called, then [NSMutableArray initialize] is called
[NSObject initialize] *is not* called, because it was already called
during the previous statement.
*/
[[MyClass alloc] init];
/*
Directly before [MyClass alloc] is called, [MyClass initialize] is
called, which causes [NSString initialize] to be called.
[NSObject initialize] *is not* called, because it was already called
during the previous statement.
/*
}
I would like to create an object containing a list of a subset of my
classes, and initialize seems like a natural place to do it. But this
means I have to find a way to lay the foundation for the
object/structure managing the registry before init is called for any
of the classes I am interested in. Anyone have suggestions for this?
--
http://homepage.mac.com/clarkcox3/
email@hidden
Clark S. Cox, III
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.