Thursday, October 02, 2008

iPhone dev 8

My iPhone and Mac Mini will arrive today. Might be disruptive to my Cocoa study.

"Sometimes using a protocol can avoid subclassing". Not sure what that means, not sure what "delegates" are. Code is in .m files, headers in .h files. Saw how to declare classes. Instead of C-style "#include", "#import" is used instead. It's like require_once in PHP.

#import
-- function and data type declarations --
@interface ClassName : Superclass {
-- instance variables --
}
-- method and property declarations --
@end

The .m file could then look something like this:

#import "ClassName.h"
@implementation ClassName
-- stuff --
@end

If I see "IBOutlet" in code later, that is somehow related to "nib files" and the Interface Builder synchronizing with Xcode. Vague at this point. Documentation mentioned that on the iPhone the applicationWillTerminate method gets called when the app shuts down and is the place where state should be saved.

Getters and setters can be automatically synthesized. "copy" and "retain" tell whether object variables should be copied or if the pointer should be stored instead and retain count incremented. Something very strange was mentioned about "KVB", "KVC" and "KVO" that I had no idea about.

Cool thing: in printf strings you can say %@ and then provide an object, and at that point any string returned by that object's "description" method will be inserted. There was a page about threads. Said exceptions should be handled by each thread, cannot be thrown away from thread. Talked about how error-prone thread programming is, that I should copy data and try to minimize possible conflicts arising from shared data. Events should just be handled by main thread, also UIKit objects should only be used in main thread. I imagine I may use threads with socket programming. Said not all Cocoa classes are thread safe.