Objective-C notes
Apple coding guidelines
Tips
- Debugging "Magic" Technote:
http://developer.apple.com/library/ios/#technotes/tn2010/tn2239.html
- Control "click" on File's Owner to see available "Outlets" and "Received Actions".
- Control "." when typing will cycle through code completion suggestions.
GDB
- Print out object values:
String Formatting
- Objective-C uses the C printf style syntax:
Terminology
- From Stanford lecture slides
| Message expression | [receiver method:arguement] |
| Message | [receiver method:arguement] |
| Selector | [receiver method: arguement] |
| Method | The code selected by a message |
Memory Management
- See:
http://interfacelab.com/objective-c-memory-management-for-lazy-people/
dealloc
- If you alloc some object, it is your responsibility to dealloc it.
dealloc order
- Put local properties first, before any super calls.
Set properties to nil in dealloc
- In the dealloc class methods set all properties to nil.
- This is important if other classes are accessing the properties, makes sure things are reset.
Use autorelease
- Action: Use alloc - init - autorelease when creating NSStrings, NSNumbers etc.
- Reason: System manages releasing the objects for you.
- What is there a difference between these calls?
- Is the numberWithFloat autoreleased too?
arrayWithObjects: vs arrayWithObject:
- arrayWithObjects: requires a nil to end the set.
Using pragma mark
- Group delegate methods together
- Group methods overridden from each parent class together
- Group new methods by functionality
enums
- Really good explaination here: http://stackoverflow.com/questions/707512/typedef-enum-in-objective-c
logging
- Add this macro to your pch file:
- Then define a Debug=DEBUG key value pair in Build Settings, under Preprocessor Macros.
Labels:
None
