Re: Class vs +class: Cocoa/Obj-C design question
Re: Class vs +class: Cocoa/Obj-C design question
- Subject: Re: Class vs +class: Cocoa/Obj-C design question
- From: Bill Bumgarner <email@hidden>
- Date: Sat, 13 Oct 2007 14:56:13 -0500
On Oct 13, 2007, at 12:17 PM, Chris Ryland wrote:
Can I ask perhaps a "list in the mists of time" language/library
question? (Or perhaps a dumb question--forgive me if so.)
Why can't a class name (e.g., NSObject) stand for itself in general--
i.e., why isn't NSObject == [NSObject class] the way +class is
defined now?
In theory, NSObject is a class object, and [NSObject class] should
be its metaclass.
Why this breakdown in what otherwise is a very clean language/
library design?
Classes can be every bit as dynamic as instances.
Through posing or any of a number of other mechanisms, the 'isa'
pointer of a class -- the thing returned by [NSObject class] -- can
easily change at runtime.
Thus, you should always use [ClassName class] or
NSClassFromString(@"ClassName") to grab a reference to the class as
doing so will always return the correct result regardless of what
might have been dynamically loaded or modified since the original link.
b.bum
_______________________________________________
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