2009-04-10 11 views
1

私は、次のオブジェクトがあります。私は「タイトル= [pSomeObjectタイトル]を割り当てるいたときにコピーが起動されていない理由を私は理解していないなぜ "コピー"が呼び出されていないのですか?

@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 

@interface SomeObject : NSObject 
{ 
    NSString *title; 
} 

@property (copy) NSString *title; 

@end 

をそして、私は別のオブジェクトを持っています"私はいつも私がプロパティに "コピー"を設定すると、常に呼び出されると思っていました。コードに誤りがありますか、何か分かりません。

ありがとうございます。

答えて

3

セッターを呼び出すにはドットの表記を使用する必要があります。

pSomeObjectため ドット表記を使用する
self.title = [pSomeObject title]; 

か...あまりにも

self.title = pSomeObject.title; 
+0

は私が違いを知りませんでした、ありがとうございます。 –

関連する問題