Objective-C Notes

Skip to end of metadata
Go to start of metadata

Objective-C notes

Apple coding guidelines

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html

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:

Reference:
http://stackoverflow.com/questions/56472/sending-messages-to-objects-while-debugging-objective-c-in-gdb-without-symbols

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

logging

  • Add this macro to your pch file:
  • Then define a Debug=DEBUG key value pair in Build Settings, under Preprocessor Macros.
Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.