• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Class vs +class: Cocoa/Obj-C design question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Class vs +class: Cocoa/Obj-C design question


  • Subject: Re: Class vs +class: Cocoa/Obj-C design question
  • From: Chris Suter <email@hidden>
  • Date: Tue, 16 Oct 2007 15:19:19 +1000


On 16/10/2007, at 2:51 PM, Bill Bumgarner wrote:

On Oct 15, 2007, at 11:23 PM, Chris Suter wrote:
But, after posing, there's still no difference between using NSObject and [NSObject class] so it doesn't prove that there are cases where

NSObject != [NSObject class]

Can you think of another example that does?

I'm not sure what you are asking.

Well, the OP said:

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?

to which you replied:

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.

and gave the example that you did.

What I was trying to say was that it wasn't clear to me how your example and explanation answered the original question since after posing, [NSObject class] and NSObject are the same thing (where the compiler permits of course).

e.g. after posing

[NSObject alloc]

and

[[NSObject class] alloc]

are identical.

So, going back to the original question, is there a circumstance where NSObject isn't the same as [NSObject class]?

- Chris

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

  • Follow-Ups:
    • Re: Class vs +class: Cocoa/Obj-C design question
      • From: Bill Bumgarner <email@hidden>
References: 
 >Class vs +class: Cocoa/Obj-C design question (From: Chris Ryland <email@hidden>)
 >Re: Class vs +class: Cocoa/Obj-C design question (From: Bill Bumgarner <email@hidden>)
 >Re: Class vs +class: Cocoa/Obj-C design question (From: Chris Ryland <email@hidden>)
 >Re: Class vs +class: Cocoa/Obj-C design question (From: Bill Bumgarner <email@hidden>)
 >Re: Class vs +class: Cocoa/Obj-C design question (From: Chris Suter <email@hidden>)
 >Re: Class vs +class: Cocoa/Obj-C design question (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: Class vs +class: Cocoa/Obj-C design question
  • Next by Date: Button enabled.
  • Previous by thread: Re: Class vs +class: Cocoa/Obj-C design question
  • Next by thread: Re: Class vs +class: Cocoa/Obj-C design question
  • Index(es):
    • Date
    • Thread