Learning Cocoa with Objective-C 这本书我差不多读了一半,感觉这本书比较像一本参考书,要做某个功能可以参考下了解一下基本的东西。跳过了一些章节,把自己之前不知道的一些东西记一下。
NSData
NSData contains bytes with no assumptions of the type of data.
NSData itself is useless
NSCoding
Serialization and Deserialization in Cocoa
Working with NSData
Using NSBundle to find resources
|
|
MultiTasking on iOS
|
|
Any task like saving to disk needs to be performed at this moment. Background app can be killed at anytime and no code can be executed at while being suspended.
Request to run in background
App can request to run in background for no more 10 mins
Tasks that can run for a longer time
- playing audio
- tracking location
- VoIP
Nib
Nib – “freeze-drying” objects and storing them in a serialized form inside the file.
When displaying, loads the nib file, “rehydrates” the stored bojects, and presents them to the user.
How Nib Files are Loaded
- re-create every objects in the nib
- connect evey outlet
- every single object loaded receives awakeFromNib: message
Blocks
|
|
Blocks exist in stack when created, thus then assign to like instance variable, the block needs to be copied to the heap.
Blocks keep strong ref to variables captured.
To modify captured variables, add __block modifier.
|
|
KVC
- accessing key that doesn’t exist causes exception
- is able to access even private vriables12345// determine the varibale to set/get at run timefor (NSString * key in dict) {NSObject *value = [dict objectForKey:key];[aProduct setValue:value forKey:key];}
KVO
- synthesized property auto notify changes when setter is called
- overried setter -> needs to fire notifiction manually12345- (void)setName:(NSString *)name {[self willChangeValueForKey:@"name"];_name = name;[self didChangeValueForKey:@"name"];}
NSNotification
broadcast notifications, typically one singleton notification center.