Based on some examples, (primarily in Aaron’s book) I had the idea that an overridden -init was somehow called at startup. When I tried it on my own, it didn’t work that way.
When I tried it out, I created a class Foo with an -init, with nothing in the ProjectAppDelegate class from NSObject that Xcode supplies and no IB. I expected it to somehow be called at startup.
Nothing happened. I think that it did nothing because nothing called my -init at startup. When I added a call to -init from ProjectAppDelegate, it ran correctly.
I’m wondering why the examples’ -init method run at startup, and mine don’t?
initis the conventional name for the method that initializes objects — for example, you create an NSMutableArray with[[NSMutableArray alloc] init]. It will only be called at startup for objects that are created at startup. If you have code that you want to run when your program starts, you’d put it in your application delegate’sapplicationDidFinishLaunchingmethod.