문제

Is it recommended to use assign property or variables? For example :

@property(assing,nonatomic)int num;

or declare the int variable at the implementation :

@implementaion {
int num;
}
도움이 되었습니까?

해결책

In general, if you want to expose things to other objects (i.e. other view controllers or things that touch this object), you can use "@property".

If you want the data to stay internal to the object, use an ivar.

Obviously my answer is greatly simplified, but @property also comes with extra goodness like ARC (retaining the object or doing atomic vs. non-atomic). In my own code, I'm using @property more and more and ivars less and less.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top