Note that there are some explanatory texts on larger screens.

plurals
  1. POStrings end up as nulls
    primarykey
    data
    text
    <p>I have a sequence of code. In it there are custom objects: <code>Item</code> and <code>ItemList</code>. The relevant members of these are <code>Item.code</code> and <code>ItemList.ItemDictionary</code>. <code>Item.code</code> is simply a <code>NSString</code> code (Like "AVK") that uniquely identifies an <code>Item</code>. These <code>Items</code> are separated into categories. There are 4 categories (Named "CatOne", etc). The <code>ItemDictionary</code> is a dictionary with the category names as keys and an <code>NSMutableArray</code> as the object; the array is filled with <code>Item</code> objects that are part of the category.</p> <p>The basic problem is that when I try to access the <code>Item.code</code>, the string comes out as <code>(null)</code>.</p> <p>The functionality is that I have an array of updated <code>Items</code> (<code>updatedItems</code>) and I want to update the <code>ItemList.ItemDictionary</code> with these new Items.</p> <p>The following are all properties of the object, and are synthesized in the main file.</p> <pre><code>@synthesize ItemListFromFile; @synthesize upDatedItems; @synthesize tempPassedManifest; </code></pre> <p>And the code:</p> <pre><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" is category Number for (int i=1; i &lt;= [Number of Categories]; i++) { NSString *currentCategoryName = [Get Category Name]; //This works... // ********* Debug statements ************ // This Loop is where NSLog shows something's not right // These conditions work fine. for (int j = 0; j &lt; [[ItemListFromFile.ItemDictionary objectForKey:currentCategoryName] count]; j++) { // This Log outputs (null) when it should output the code from the Item NSLog(@"Code from File: %@", [[[ItemListFromFile.ItemDictionary objectForKey:currentCategoryName] objectAtIndex:j] code]); } // ************** Debug ****************** if ([[ItemListFromFile.ItemDictionary allKeys] containsObject:currentCategoryName]) { [oldItemArray setArray:[ItemListFromFile.ItemDictionary objectForKey:currentCategoryName]]; for (Item *anItem in oldItemArray) { NSLog(@"OldItemArray Code: %@", anItem.code); } } else { [oldItemArray removeAllObjects]; } [newItemArray removeAllObjects]; // Go through each Item in category i. for (NSString *currentCode in [array of codes in category i (this works)]) { // There's two options of where to grab each Item from: either upDatedItems or oldItemArray BOOL inOldArray = YES; for (Item *anItem in upDatedItems) { if ([anItem.code isEqualToString:currentCode]) { [newItemArray addObject:anItem]; inOldArray = NO; NSLog(@"%@ was in updatedItems", currentCode); break; } } if (inOldArray) { // Checking in old Item Array for (Item *anItem in oldItemArray) { NSLog(@"Checking %@ against %@", anItem.code, currentCode); // (anItem.code is null) if ([anItem.code isEqualToString:currentCode]) { [newItemArray addObject:anItem]; NSLog(@"%@ was in oldItems", currentCode); break; } } } } //We've created the array, so add it to dictionary [ItemListFromFile.ItemDictionary setObject:newItemArray forKey:currentCategoryName]; NSLog(@"New Dance Array: %@", newDanceArray); } [NSKeyedArchiver archiveRootObject:ItemListFromFile toFile:tempPassedManifest.ItemListSavePath]; } </code></pre> <p>I've tried to be as thorough as possible, but do not hesitate to ask for clarification.</p> <h2>Update</h2> <p>I've been trying a lot of solutions to this, but nothing seems to be working. Things I've tried:</p> <ul> <li>Creating an object that takes the place of <code>*anItem</code>, so instead of a <code>for</code> loop that loops through the contents of the array, loops from <code>i=0..[Count]</code>, and then sets the object at that index to the item I created before the loop. I thought this might help so that I could allocate and initialize the <code>Item.code</code> before setting it to whatever the Item has.</li> <li><p>Using </p> <pre><code>oldItemArray = [ItemListFromFile.ItemDictionary objectForKey:currentCategoryName]; </code></pre> <p>instead of</p> <pre><code>[oldItemArray setArray:[ItemListFromFile.ItemDictionary objectForKey:currentCategoryName]]; </code></pre></li> <li><p>I tried updating all of the items in the <code>ItemList.ItemDictionary</code> so that when it archives, all of the items are fresh for the next trial run of the code.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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