je l'objet suivant:Pourquoi "copier" n'est pas invoqué?
@interface SomeObject : NSObject
{
NSString *title;
}
@property (copy) NSString *title;
@end
Et j'ai un autre objet:
@interface AnotherObject : NSObject{
NSString *title;
}
@property (copy) NSString *title;
- (AnotherObject*)init;
- (void)dealloc;
- (void) initWithSomeObject: (SomeObject*) pSomeObject;
+ (AnotherObject*) AnotherObjectWithSomeObject (SomeObject*) pSomeObject;
@end
@implementation AnotherObject
@synthesize title
- (AnotherObject*)init {
if (self = [super init]) {
title = nil;
}
return self;
}
- (void)dealloc {
if (title) [title release];
[super dealloc];
}
-(void) initWithSomeObject: (SomeObject*) pSomeObject
{
title = [pSomeObject title]; //Here copy is not being invoked, have to use [ [pSomeObject title] copy]
}
+ (AnotherObject*) AnotherObjectWithSomeObject (SomeObject*) pSomeObject;
{
[pSomeObject retain];
AnotherObject *tempAnotherObject = [ [AnotherObject alloc] init];
[tempAnotherObject initWithSomeObject: pSomeObject];
[pSomeObject release];
return tempAnotherObject;
}
@end
Je ne comprends pas, pourquoi la copie n'est pas invoqué lorsque j'assigne « title = [title pSomeObject] ". J'ai toujours pensé que si je mettais "copier" dans la propriété, il serait toujours invoqué. J'ai une erreur dans mon code ou je ne comprends pas quelque chose?
Merci à l'avance.
Merci, je ne savais pas la différence. –