objective c - How should I construct an NSDictionary with multiple keys? -
I have a situation where I want to map a pair of items for a dictionary of information. I would like to avoid creating an NSDictionary of NSDictionaries of NSDictionaries because it is only confusing and difficult to maintain. For example, if I have two squares, foo and bar, let me know {Foo, Bar} -> {NSDictionary}
Want to have a choice other than just creating a custom class (Can only be used as a dictionary key on the basis of two types of question? Probably like the pair of STL Something that I'm not right now As you said, you can create a pair of classes:
// Pair.h @ Interface pair: NSPacked & lt; encoding & gt; {ID & lt; encoding> left; ID & lt; NSCopying & gt; Correct;} @ Property (Nonomatic, Readonly) ID & lt; NScoping & gt; Left; @ Property (Nonomatic, Readonly) ID & lt; NScoping; Right; + (ID) pair with lift: (ID & lt; NSCPIP & gt;) L Correct: & Lt; nspip & gt; R; - (ID ) InitWithLeft: (ID & lt; Ansseepiaipi & gt;) L Right (ID & lt; NCPPing & gt;) R; @ And // pir.m # Imports "Pair H." @Epilmentation pair @ Synthesize left, right; + (ID) pair with lift: (id & lieutenant; nscpijg) l correct: (id & lieutenant; ncpip> gt; r [return [[sg class]] allok with input: lift: r ] AutoWrecks]; } - (id) initWithLeft: (ID & Lt; NSCPIG & gt;) El Correct: (id & lt; NCPPI) R {if (self = [super init]) {left = [l copy]; Right = [r copy]; } Healthy return; } - (zero) finally {[left release], left = zero; [Right release], right = zero; [Super final form]; } - (zero) Delok [[left release], left = zero; [Right release], right = zero; [Super DeLoc]; } - (ID) Copywritz zone: (NSZEN *) region {pair} * copy = [[self class] incoming] initWithLeft: [self remaining] true: [self correct]]; Return copy; } - (BOOL) is aqual: (id) other {if ([Other Hackandoff class: [pair class]] == no {return not; } Return ([[Self left] is Acqual: [other left]] & [[Self correct] is Acqual: [Other rights]]); } - (NSUntengar) hash (probably probably "hashish") is not enough, but possibly sufficient enough return [[self left] hash] + [[self right] hash]; } @end
Edit:
Some notes on the making of such things which can be keys:
- call them
Encode the protocol
, since we want us to change the key from the down side.- Since the pair has been copied, I'm sure the objects are also copied in the pair.
- Keys have to be executed
is Excel:
. I apply thehash
method to good measure, but it is probably not necessary.
Comments
Post a Comment