Basic Principles in Writing Object-C codes

1. Code should be designed to be read out loud from left to right and make sense.app

2. The app needs save critical data it's working on when it's told to enter background, because the app might be terminated while it's suspended.this

3. property attributesatom

strong: variable stays in memory
orm

weak: when the object is deallocated, property variable is set to nil automaticallyget

assign: perform no memory copyit

copy: perform memory copyform

readwrite: both getter and setter methods are generatedclass

readonly: only getter method is generatedthread

nonatomic: no lock, not thread-safeobject

4. proptery variable reference

If it's a member of parent class, self.xxxx;

If it's this class' property, _xxxx or self.xxxx, the former is preferred.

If it's not a property, but only a variable, xxxx;

相關文章
相關標籤/搜索