Basic Principles in Writing Object-C codes

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

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.

3. property attributes

strong: variable stays in memory

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

assign: perform no memory copy

copy: perform memory copy

readwrite: both getter and setter methods are generated

readonly: only getter method is generated

nonatomic: no lock, not thread-safe

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;






你可能感兴趣的:(Basic Principles in Writing Object-C codes)