NSDictionary(FSNSDictionaryPairs) |
The FSNSDictionaryPairs category adds class methods to NSDictionary that make it easier to create dictionaries from arrays.
Extends Class: NSDictionary
Declared In: FSNSDictionaryPairs.h
dictionaryWithFlatPairs: |
+ (NSDictionary*) dictionaryWithFlatPairs:(NSArray*)flatPairs;
Like dictionaryWithPairs:, but assumes that flatPairs is a one-dimensional array that holds alternating keys and values. This makes it easy to initialize a dictionary from an array, in the manner of Perl::
myDictionary := NSDictionary dictionaryFromPairs:{ 'key1', item1, 'key2', 'item2', 'key3', 3 }.
This method is similar to NSDictionary dictionaryWithKeysAndObjects:, except that this method uses an NSArray rather than C variadic argument lists, which are not valid in F-Script.
dictionaryWithPairs: |
+ (NSDictionary*) dictionaryWithPairs:(NSArray*)pairs;
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 := NSDictionary dictionaryWithPairs:lines.
© Andrew Weinrich Last Updated: Wednesday, October 15, 2008