Ich habe folgendes Objekt:Warum wird "Kopieren" nicht aufgerufen?
@interface SomeObject : NSObject
{
NSString *title;
}
@property (copy) NSString *title;
@end
Und ich habe ein anderes Objekt:
@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
Ich verstehe nicht, warum Kopie nicht, wenn ich „title = [pSomeObject title] Zuordnung bin aufgerufen wird ". Ich dachte immer, wenn ich "Kopie" in der Eigenschaft setze, wird es immer aufgerufen. Ich habe einen Fehler in meinem Code oder ich verstehe etwas nicht?
Vielen Dank im Voraus.
Danke, habe ich den Unterschied nicht kennen. –