Comparison of programming languages (associative array): Difference between revisions

Content deleted Content added
Objective-C (Cocoa/GNUstep): copy editing and linking
Objective-C (Cocoa/GNUstep): copy editing and (crudely) referencing
Line 1,073:
 
===Objective-C (Cocoa/GNUstep) ===
[[Cocoa (API)|Cocoa]] and [[GNUstep]], written in [[Objective-C]], handle associative arrays using <code>NSMutableDictionary</code> (a mutable version of <code>NSDictionary</code>) class cluster. This class allows assignments between any two objects. A copy of the key object is made before it is inserted into <code>NSMutableDictionary</code>, therefore the keys must conform to the <code>NSCopying</code> protocol. When being inserted to a dictionary, the value object receives a retain message to increase its reference count. The value object will receive the release message when it will be deleted from the dictionary (botheither explicitly or by adding to the dictionary a different object with the same key).
 
<syntaxhighlight lang=ObjC>
Line 1,082:
</syntaxhighlight>
 
To access assigned objects, this command may be used:
 
<syntaxhighlight lang=ObjC>
Line 1,088:
</syntaxhighlight>
 
All keys or values can be simply enumerated using <code>NSEnumerator</code>:
 
<syntaxhighlight lang=ObjC>
Line 1,099:
</syntaxhighlight>
 
OnIn Mac OS X 10.5+ and iPhone OS, dictionary keys can also be enumerated more concisely using thisthe [<code>NSFastEnumeration</code> construct:<ref>https://developer.apple.com/documentation/Cocoa/Reference/NSFastEnumeration_protocol/</ref> NSFastEnumeration] construct:
 
<syntaxhighlight lang=ObjC>
Line 1,122:
</syntaxhighlight>
 
And relevantRelevant fields can be quickly accessed using key paths:
 
<syntaxhighlight lang=ObjC>