> On Mar 29, 2017, at 6:57 AM, Daryle Walker <[email protected]> wrote:
> 
> Sometimes, I see something in Apple’s AppKit/Foundation reference site that 
> mentions that their technique should be loaded early in the program by 
> putting it in the class’s “+initiallize” method.

A +initialize method doesn’t necessarily run early in the program; it runs 
before the first time a method of that class is called. But that class might 
not be called until later in the process, or never. So +initialize is useful 
for setting up state that this specific class will depend on — like 
initializing static variables — but not for program-wide dependencies.

There’s a more obscure method +load that _does_ get called when the process 
starts up (at roughly the same time as C++ static initializer methods.) Its use 
is discouraged because doing stuff at launch time is bad for responsiveness, 
and because it’s easy to run into problems with dependencies on other stuff 
being initialized already, like if your +load method calls something in AppKit 
that hasn’t been initialized yet because _its_ +load method runs after yours...

> Now the new Xcode release notes say that “• Swift now warns when an NSObject 
> subclass attempts to override the initialize class method, because Swift 
> can't guarantee that the Objective-C method will be called. (28954946)”

Huh, I haven’t heard of that. And I’m confused by “the Objective-C method” — 
what’s that? Not the +initialize method being compiled, because that’s in 
Swift. The superclass method?

Guess I’ll follow that Radar link and read the bug report myself. Oh, wait. :(

I suggest asking on the swift-users list, because this seems like something to 
do with the Swift runtime, or at least the details of how Swift binds with 
Obj-C.

—Jens
_______________________________________________

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

This email sent to [email protected]

Reply via email to