Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am not sure what you're really asking here, but let's see if any of the following helps.</p> <p>First consider this method based on your code fragment:</p> <pre><code>- (void) test { NSMutableArray *Array1 = [NSMutableArray new]; NSMutableArray *Array2 = [NSMutableArray new]; [Array1 addObject:@"Hello"]; [Array1 addObject:@"There"]; [Array2 addObject:@"Hi"]; [Array2 addObject:@"Welcome"]; NSMutableDictionary *dictionaryOfArrays = [NSMutableDictionary new]; [dictionaryOfArrays setObject:Array2 forKey:Array1]; // arrays are ordered, use key with elements in different order to show this [dictionaryOfArrays setObject:Array2 forKey:@[@"There", @"Hello"]]; NSLog(@"dictionary: %@", dictionaryOfArrays); } </code></pre> <p>This will output to the console:</p> <pre><code>dictionary: { ( There, Hello ) = ( Hi, Welcome ); ( Hello, There ) = ( Hi, Welcome ); } </code></pre> <p>The shows that the <em>key</em> can be an array - and the order of elements in the array is important.</p> <p>However do you really want to use arrays as keys? While having the <em>values</em> as arrays is common, it is not common for the key to be an array as well.</p> <p>You say you are getting either <code>( )</code> or "null". Well the first of those could be an array with no elements - which is distinct from no array. As to the second, you cannot store <code>nil</code> in a <code>NSDictionary</code> but if you look up a value for a non-existant key then <code>nil</code> is returned - i.e. a <code>nil</code> return means a non-existant key.</p> <p>Finally in case it is relevant, when a key/value pair is added to a dictionary the key is <em>copied</em> while the value is simply <em>referenced</em>. This means that if you use a mutable object as a key, e.g. a <code>NSMutableString</code> instance, then subsequent mutations of the object do not effect the dictionary. However if the value (of the key/value pair) is a mutable object then a lookup operation returns the exact same object as was inserted, which could have been mutated since insertion.</p> <p>The code you've added to your question doesn't clarify at all.</p> <p>Hope something here helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload