• 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: On self = [super init...] ...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: On self = [super init...] ...


  • Subject: Re: On self = [super init...] ...
  • From: Thomas Davie <email@hidden>
  • Date: Thu, 18 Nov 2010 21:40:53 +0000

On 18 Nov 2010, at 21:16, Bill Bumgarner wrote:

>
> On Nov 18, 2010, at 1:10 PM, John Engelhart wrote:
>
>> The basic premise behind self = [super init...] is that the "lower levels of initialization are free to return a different object than the one passed in".
>>
>> However, there is an unstated assumption in this reasoning: whatever object is returned by [super init...] is the one that will be used.
>
>
> I don't understand the above claim; Why must the object returned by [super init*] be the one that is used?
>
> I'm certainly not aware of any limitation on an init method that would prevent it from… say… calling [super init], releasing whatever is returned if deemed unfit and then allocating an initializing some other instance.
>
> The documentation (http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/ObjectiveC/Articles/ocAllocInit.html) doesn't seem to make any such claim either.
>
> I haven't read beyond the above yet.  Maybe the unstated assumption is explained?

Indeed, the behaviour of immutable strings and containers seem to back up this assertion

#import <Foundation/Foundation.h>

int main (int argc, char ** argv)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSString *s1 = @"";
    NSString *s2 = [NSString stringWithString:s1];
    NSString *s3 = [NSString alloc];
    NSString *s4 = [s3 initWithString:s2];

    NSLog(@"%p, %p, %p, %p", s1, s2, s3, s4);

    [pool drain];
}

prints 2010-11-18 21:39:35.767 Test[18767:a0f] 0x100001050, 0x100001050, 0x10010d470, 0x100001050

So our allocated string is certainly substituted during initialisation.

Bob_______________________________________________

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: 
 >Re: On self = [super init...] ... (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: Calling a class method with the runtime ObjC API
  • Next by Date: Re: Calling a class method with the runtime ObjC API
  • Previous by thread: Re: On self = [super init...] ...
  • Next by thread: Re: On self = [super init...] ...
  • Index(es):
    • Date
    • Thread