576NSDictionary and NSArray plist examples

NSDictionary





    arrayKey
    
        string1
        string2
        string3
        string4
    
    dicKey
    
        key1
        object1
        key2
        object2
        key3
        object3
    
    key2
    object2
    key3
    object3



NSArray





    string1
    string2
    string3
    
        key1
        object1
        key2
        object2
        key3
        object3
    
    string5



At the end, after </plist>, there's another CR.

246writeToFile – quick file writing

writetofile API Reference

- (BOOL)writeToFile:(NSString *)path 
         atomically:(BOOL)useAuxiliaryFile;

Works with:

NSDictionary
NSArray
NSData
NSString

For more complicated purposes, NSOutputStream might be the best option, but for simply writing a date or even XML this might be the simplest and fasted way.

243Stepping over an Array (or Dictionary)

NSArray *paths = [[NSFileManager defaultManager] 
    directoryContentsAtPath: NSHomeDirectory()];

// either like that...
NSEnumerator *e = [paths objectEnumerator];
for (NSString *p in e) {
    NSLog(@"path: %@", p);
}

// or like that.
for (NSString *p in [paths objectEnumerator]) {
    NSLog(@"path: %@", p);
}

NSDictionary has both [myDict objectEnumerator] and [myDict keyEnumerator].

Fast Enumberation is a feature in Objective-C 2.0, it allows you to step over arrays and dictionaries in a fast, consice, and secure (guarded against mutations) manner.

for (NSString *p in paths) {
    NSLog(@"path: %@", p);
}

// or

NSString *p;
for (p in paths) {
    NSLog(@"path: %@", p);
}

Sometimes things are really as simple as they should be.