book info

"Programming in Objective-C", Stephen G. Kochan, ISBN 0-672-32586-1

http://www.kochan-wood.com - examples.

http://www.cocoadevcentral.com, http://www.cocoadev.com

memory management

autorelease pool, object "init", "retain", "autorelease", "dealloc" methods. override "dealloc" to do custom release stuff.

categories, protocols, posing

Categories and posing share much in common. When overriding a method in category, you cannot access the original. When posing, you are still acting as a subclass, so you can call super methods.

"Add a category called TempFiles to NSString and define a method that returns a temporary file name":

@interface NSString (TempFiles)
-(NSString *) temporaryFileName;
@end
@implementation NSString (TempFiles)
-(NSString *) temporaryFileName {
    return [[NSTemporaryDirectory() stringByAppendingString:@"/"]
        stringByAppendingString: [[NSProcessInfo processInfo] globallyUniqueString]];
}
@end

A protocol is a list of methods that is shared among classes.

 #interface AddressBook: NSObject <NSCopying, NSCoding> 

"I am Addressbook class, based on NSObject, and I implement the NSCopying and NSCoding protocols."

Informal protocols - really no more than a grouping of methods under a name.

Composite objects - objects that have another object as their instance variable, piggybacking on its methods.

C features - variables, pointers

    struct packedStruct {
     unsigned int f1:1;
     unsigned int f2:1;
     unsigned int type:4;
     unsigned int index:9;
    }

This is a bit field, the number after colon shows number of bits. Useful for flags.

(*x).y is the same as x->y

  1. int *valuesPtr;
  2. valuesPtr = values; or valuesPtr = &values[0];

  3. now *(valuesPtr+i) accesses values[i].

Pointers to functions - useful for dispatch tables and passing to methods.

Union - like a struct, but from storage POV only one member is "active" at a time, can store alternate data types in same memory space.

foundation - strings

Dump any variable to console.

NSRange - type with ".location" and ".length", used as input when getting substrings as returned from substring search

foundation - basic data storage/manipulation objects

Each of these also has a Mutable subclass.

object copying - mutableCopy method. Need to release myself if creating object with methods "alloc", "copy", "allocWithZone:", "copyWithZone:" or "mutableCopy".

Shallow (default) vs deep copying. <NSCopying> protocol. Make copy of parameter/instance variables in setter/getter methods.

"nil" - invalid object.

archiving, plists

property list: disk-dumped version of "property list objects" (NSString, NSData, NSArray, or NSDictionary objects, or also NSNumber or NSData). Keys in dictionary must be NSString objects.

writeToFile: and blaahWithContentsOfFile: methods.

NSCopying protocol for archiving. NSKeyedArchiver. Use archiver to deep copy objects. Following is useful to deep copy an object or copy an object who doesn't support the NSCoding protocol.

    dataArray2 = [NSUnarchiver unarchiveObjectWithData:
        [NSArchiver archivedDataWithRootObject: dataArray]];

JaanusKase/Books/ProgrammingInObjectiveC (last edited 2007-02-09 20:43:04 by JaanusKase)