• 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: Another Gnarly Objective-C Question!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Another Gnarly Objective-C Question!


  • Subject: Re: Another Gnarly Objective-C Question!
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Wed, 13 Mar 2013 19:28:50 +0100

Le 13 mars 2013 à 18:13, John McCall <email@hidden> a écrit :

> On Mar 13, 2013, at 2:13 AM, Jean-Daniel Dupas <email@hidden> wrote:
>> Le 13 mars 2013 à 01:55, Wim Lewis <email@hidden> a écrit :
>>> On 12 Mar 2013, at 2:08 AM, Graham Cox wrote:
>>>> in a + method, [self class] === self. Once you've got that, you've got it.
>>>>
>>>>
>>>>
>>>> You're overthinking this.
>>>>
>>>> A class method is just an instance method of the class object. No magic at all. So all this confusion you've caused yourself about [super class] and so on is wholly unnecessary to correctly use class methods.
>>>
>>> To be very slightly pedantic, the only magic here is 'super' --- sending a message to super (which you can only do from a method implementation) is special syntax that searches for the method starting with the implementation's class's superclass, rather than at the receiver's actual class. Everything else is non-magic. (In general, that's been one of the strengths of ObjC: very little magic.)
>>>
>>
>> To be ever more pedantic, there is other magic involved when sending a message to a class.
>> If there is no class method that matches the selector, the runtime will then search for instance methods of the root class.
>
> Note that this isn't "magic" really;  it's a quirk of the type system (both formal and dynamic).  The root metaclass is a subclass of the root class.

Yes, nothing is magic if the magician reveals its tricks, that's why he should not do that  ;-)

> This can be problematic if you really want your root class to have a layout that's bigger than just an isa field, because the ABI and runtime just hardcode the layout of classes and there is no room for extra fields there — thus you need to be sure that anything using your extra fields is never invoked on a class object.

I usually avoid this kind of issue by not writing root class. The extra fields issue is not the only one that a root class can have. Even methods that do not access ivars should take care of the Class case (retain/release/autorelease for instance).

-- Jean-Daniel




_______________________________________________

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


References: 
 >Another Gnarly Objective-C Question! (From: Dave <email@hidden>)
 >Re: Another Gnarly Objective-C Question! (From: Graham Cox <email@hidden>)
 >Re: Another Gnarly Objective-C Question! (From: Wim Lewis <email@hidden>)
 >Re: Another Gnarly Objective-C Question! (From: Jean-Daniel Dupas <email@hidden>)
 >Re: Another Gnarly Objective-C Question! (From: John McCall <email@hidden>)

  • Prev by Date: KeyboardType for an iOS searchBar.
  • Next by Date: UIPopoverController
  • Previous by thread: Re: Another Gnarly Objective-C Question!
  • Next by thread: Re: Another Gnarly Objective-C Question!
  • Index(es):
    • Date
    • Thread