سؤال

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