objective c - Adding key/value Pairs results in keys with null values -


i'm having issue dictionary timestamps changes values null. keys fine, if switch key value , vice versa. no matter order, values end null , keys end should.

here's code. it's xml parser. building dictionary has array of codes keys , array of timestamps values. keys , values parallel arrays representing categories.

all variables allocated , initiated elsewhere. imports header file has of these variables properties. @property (strong, nonatomic) type variablename; in main file has line @synthesize variablename. also, has variablename = [[type alloc] init];. thank help!

- (void) didstartelement (elementname passed xml tag) {     //tells if in dance categories     if ([elementname isequaltostring:@"categories"])     {         iscategory = yes; // tells we're ready start reading      }     else if ([elementname isequaltostring:@"category"] && iscategory)      {         oncategory = yes; //      } }   - (void) foundcharacters (currentnodecontent info between tags) {     currentnodecontent = (nsmutablestring *) string; }   - (void) didendelement {     // if leaving dance categories     if ([elementname isequaltostring:@"category end"])     {         iscategory = no; // we've left category     }     else if ([elementname isequaltostring:@"code"] && oncategory)     {         code               = currentnodecontent;         currentnodecontent = nil;         iswaitingfortime   = yes;     }      else if ([elementname isequaltostring:@"time"] && iswaitingfortime)     {         [runninglist       addobject:code];         [runninglist   addobject:currentnodecontent];          iswaitingfortime   = no;         currentnodecontent = nil;         code               = @"";     }      else if ([elementname isequaltostring:@"dances"])     {         [timestamps setobject:runningtimelist forkey:runninglist];         [runningtimelist   removeallobjects];         [runninglist       removeallobjects];     } } 

i not sure you're asking here, let's see if of following helps.

first consider method based on code fragment:

- (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 ordered, use key elements in different order show    [dictionaryofarrays setobject:array2 forkey:@[@"there", @"hello"]];     nslog(@"dictionary: %@", dictionaryofarrays); } 

this output console:

dictionary: {         (         there,         hello     ) =     (         hi,         welcome     );         (         hello,         there     ) =     (         hi,         welcome     ); } 

the shows key can array - , order of elements in array important.

however want use arrays keys? while having values arrays common, not common key array well.

you getting either ( ) or "null". first of array no elements - distinct no array. second, cannot store nil in nsdictionary if value non-existant key nil returned - i.e. nil return means non-existant key.

finally in case relevant, when key/value pair added dictionary key copied while value referenced. means if use mutable object key, e.g. nsmutablestring instance, subsequent mutations of object not effect dictionary. if value (of key/value pair) mutable object lookup operation returns exact same object inserted, have been mutated since insertion.

the code you've added question doesn't clarify @ all.

hope here helps.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -