• 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: Do I need private accessor methods?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Do I need private accessor methods?


  • Subject: Re: Do I need private accessor methods?
  • From: Nir Soffer <email@hidden>
  • Date: Sat, 29 Apr 2006 18:21:47 +0300


On 29/04/2006, at 00:32, Eric Lin wrote:

This wouldn't be correct in the case that [super init] returns a different
self:


   if (self = [super init]) {
         privateVariable = 123;
   }

Well it is correct (unless I'm missing something), try this Foundation tool:


#import <Foundation/Foundation.h>

@interface Parent : NSObject
{
    NSString *value;
}
- (NSString *)value;
@end

@interface Replacement : Parent
@end

@interface SubParent : Parent
@end

@implementation Parent
-(id)init
{
    // Return another object
    NSLog(@"%@: value:%@", self, value);
    return [[Replacement alloc] init];
}
- (NSString *)value {return value;}
@end

@implementation Replacement
-(id)init
{
    value = @"a replacement";
    NSLog(@"%@: value:%@", self, value);
    return self;
}
@end

@implementation SubParent
- (id)init
{
    if ((self = [super init])) {
        value = @"a sub parent";
        NSLog(@"%@: value:%@", self, value);
    }
    return self;
}
@end


int main (int argc, const char * argv[]) { [[[SubParent alloc] init] release]; return 0; }


Best Regards,

Nir Soffer

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Do I need private accessor methods? (From: "Eric Lin" <email@hidden>)

  • Prev by Date: Re: How to access the value that a pointer is pointing to
  • Next by Date: Re: Do I need private accessor methods?
  • Previous by thread: Re: Do I need private accessor methods?
  • Next by thread: Re: Do I need private accessor methods?
  • Index(es):
    • Date
    • Thread