2012年5月12日 星期六

Objective C 學習重點

從史丹佛大學的iPhone編程課程中,所整理出來

1. Define a class’s public @interface and private @implementation in a .h and .m file respectively
2. Add a private @interface to .m file
3. Create a @property, both for a primitive type (like BOOL) and a pointer (like NSMutableArray *)
4. Use nonatomic in @property declarations
5. Use strong or weak in @property declarations of pointers to objects
6. Use @synthesize to create a @property’s setter and getter and backing instance variable
7. Use “= _propertyname”to choose the name @synthesize uses for its backing instance variable
8. For pointers to an object, use either the special type id or a static type (e.g. UIButton *)
9. Declare and define an Objective C method (e.g. pushOperand: or popOperand).
10. Declare local variables both of type “pointer to an object” (id or static type) and primitive type
11. Invoke an Objective C method (using square bracket [] notation)
12. Invoke a setter or getter using dot notation (e.g. self.operandStack or self.display.text)
13. Lazily instantiate an object by implementing your own @property getter (operandStack & brain)
14. Wrap a primitive type (like double) in an object (using NSNumber)
15. Log formatted strings to the console using NSLog() (for debug)
16. Use a “constant” NSString in your code using @“” syntax (e.g. @“+”)
17. Add and remove an object from an NSMutableArray (the last object anyway ).
18. Use alloc and init to create space in the heap for an object (well, you’ve barely learned this).
19. #import the .h file of one class into another’s (CalculatorBrain.h into your Controller)
20. Create a string by asking a string to append another string onto it
21. Create a string with a printf-like format (e.g., [NSString stringWithFormat:@“%g”, result])

沒有留言: