NSMutableDictionary(FSNSMutableDictionary)


The FSNSMutableDictionary category adds class methods to NSMutableDictionary that make it easier to create dictionaries from arrays

Extends Class: NSMutableDictionary
Declared In: FSNSMutableDictionary.h



Methods

+dictionaryWithFlatPairs:
+dictionaryWithPairs:

dictionaryWithFlatPairs:


+ (NSMutableDictionary*) dictionaryWithFlatPairs:(NSArray*)flatPairs; 
Discussion

Like dictionaryWithPairs:, but assumes that flatPairs is a one-dimensional array that holds alternating keys and values. The following (contrived) code is equivalent to the example for dictionaryWithPairs::

configDataString := '.......'
"Split configuration apart on either newline or delimiter " keysAndValues := configDataString split:' += +|\n'.
config := NSMutableDictionary dictionaryWithFlatPairs:keysAndValues.


This method is similar to NSDictionary dictionaryWithKeysAndObjects:, except that that method uses C variadic argument lists rather than an NSArray.


dictionaryWithPairs:


+ (NSMutableDictionary*) dictionaryWithPairs:(NSArray*)pairs;
Discussion

Creates a dictionary from pairs, which must be an array of arrays, each second-level array containing exactly two elements (the key and value). For example, say that you need to read a configuration file that is in the format keyName = value. The following code will create a dictionary that holds the configuration:

file := FSFile open:'....'.
lines := [ :line | line split:' += +' ] value: (file readlines).
config := NSMutableDictionary dictionaryWithPairs:lines.

© Andrew Weinrich Last Updated: Wednesday, October 15, 2008