Re: Do I need private accessor methods?
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