2011-09-03 6 views
0

인스턴스 변수로 바꾸려는 개체가 있습니다.왜이 개체를 인스턴스 변수로 변환 할 수 없습니까?

ZipFile *newZipFile = [[ZipFile alloc] initWithFileName:zipPath mode:ZipFileModeCreate]; 

을하지만이로 변경하려고 할 때 작동하지 않습니다 :이 작동

.H :

@interface PanelController : NSWindowController <NSWindowDelegate> { 
    ZipFile *_zipFile; 
} 
@property (nonatomic, assign) ZipFile *zipFile; 

하는 .m :

@synthesize zipFile = _zipFile; 
... 
// get a syntax error here 
zipFile = [[ZipFile alloc] initWithFileName:zipPath mode:ZipFileModeCreate]; 

편집을 : 나는 이것을 인터페이스에 넣고 @property를 제거함으로써 이것을 해결할 수 있었다 :

ZipFile *newZipFile; 

나는 모든 개체에 setter 및 getters를 할당 할 수 없다고 생각합니까? 그러나 내가하는 경우 왜 작동하지 않습니다 :

ZipFile *zipFile; 

답변

5

zipFile라는 ivar가 없습니다. 당신이 찾으 셨나요?

_zipFile = [[ZipFile alloc] initWithFileName:zipPath mode:ZipFileModeCreate]; 

나 :

self.zipFile = [[[ZipFile alloc] initWithFileName:zipPath mode:ZipFileModeCreate] autorelease]; 

참고 : 당신은 아마 당신의 재산이 retain되고 싶어요. assign은 소유하지 않은 속성 (예 : 대리인) 용입니다. assign 속성이 쉽게 매달려 포인터가 될 수 있기 때문에 안전하지 않습니다. 귀하의 @synthesize

3
@synthesize zipFile = _zipFile; 
... 
// get a syntax error here 
zipFile = [[ZipFile alloc] initWithFileName:zipPath mode:ZipFileModeCreate]; 

는 속성이 zipFile라는 있지만, 변수지지 그것이 _zipFile 것을 말한다.

변수가 zipFile이 아니므로 할당 행이 잘못되었습니다.

_zipFile = [[ZipFile alloc] initWithFileName:zipPath mode:ZipFileModeCreate]; 

이 맞습니다.

관련 문제