ios - Strings end up as nulls -


i have sequence of code. in there custom objects: item , itemlist. relevant members of these item.code , itemlist.itemdictionary. item.code nsstring code (like "avk") uniquely identifies item. these items separated categories. there 4 categories (named "catone", etc). itemdictionary dictionary category names keys , nsmutablearray object; array filled item objects part of category.

the basic problem when try access item.code, string comes out (null).

the functionality have array of updated items (updateditems) , want update itemlist.itemdictionary these new items.

the following properties of object, , synthesized in main file.

@synthesize itemlistfromfile; @synthesize updateditems; @synthesize temppassedmanifest; 

and code:

-(id) updateditems:(nsarray *)newitems manifest:(manifest *)manifest {  itemlistfromfile = [[itemlist alloc] init]; itemlistfromfile.itemdictionary = [[nsmutabledictionary alloc] init]; itemlistfromfile = [nskeyedunarchiver unarchiveobjectwithfile:manifest.itemlistsavepath]; updateditems = newitems temppassedmanifest = manifest;  [self updateitemlist];  return self;  }  -(void)updateitemlist {  nsmutablearray *newitemarray = [[nsmutablearray alloc] init]; nsmutablearray *olditemarray = [[nsmutablearray alloc] init];  // go through each category. "i" category number (int i=1; <= [number of categories]; i++) {             nsstring *currentcategoryname = [get category name]; //this works...      // ********* debug statements ************      // loop nslog shows something's not right      // these conditions work fine.     (int j = 0; j < [[itemlistfromfile.itemdictionary objectforkey:currentcategoryname] count]; j++)     {         // log outputs (null) when should output code item         nslog(@"code file: %@", [[[itemlistfromfile.itemdictionary objectforkey:currentcategoryname] objectatindex:j] code]);     }     // ************** debug ******************      if ([[itemlistfromfile.itemdictionary allkeys] containsobject:currentcategoryname])     {         [olditemarray setarray:[itemlistfromfile.itemdictionary objectforkey:currentcategoryname]];          (item *anitem in olditemarray)         {             nslog(@"olditemarray code: %@", anitem.code);         }     }     else     {         [olditemarray removeallobjects];     }      [newitemarray removeallobjects];       // go through each item in category i.     (nsstring *currentcode in [array of codes in category (this works)])     {          // there's 2 options of grab each item from: either updateditems or olditemarray          bool inoldarray = yes;          (item *anitem in updateditems)         {             if ([anitem.code isequaltostring:currentcode])             {                 [newitemarray addobject:anitem];                 inoldarray = no;                 nslog(@"%@ in updateditems", currentcode);                 break;             }         }         if (inoldarray)         {         // checking in old item array             (item *anitem in olditemarray)             {                 nslog(@"checking %@ against %@", anitem.code, currentcode);                 // (anitem.code null)                  if ([anitem.code isequaltostring:currentcode])                 {                     [newitemarray addobject:anitem];                     nslog(@"%@ in olditems", currentcode);                     break;                 }             }         }     }     //we've created array, add dictionary     [itemlistfromfile.itemdictionary setobject:newitemarray forkey:currentcategoryname];     nslog(@"new dance array: %@", newdancearray); }  [nskeyedarchiver archiverootobject:itemlistfromfile tofile:temppassedmanifest.itemlistsavepath];  } 

i've tried thorough possible, not hesitate ask clarification.

update

i've been trying lot of solutions this, nothing seems working. things i've tried:

  • creating object takes place of *anitem, instead of for loop loops through contents of array, loops i=0..[count], , sets object @ index item created before loop. thought might allocate , initialize item.code before setting whatever item has.
  • using

    olditemarray = [itemlistfromfile.itemdictionary objectforkey:currentcategoryname]; 

    instead of

    [olditemarray setarray:[itemlistfromfile.itemdictionary objectforkey:currentcategoryname]]; 
  • i tried updating of items in itemlist.itemdictionary when archives, of items fresh next trial run of code.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -