Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to add entries in NSArray to NSDictionary, but values in NSDictionary are getting deallocated
    primarykey
    data
    text
    <p>I have three Deck Objects which are mostly just wrappers around NSArray objects containing Card objects. Initially, all the Card objects are in deck1, and eventually move through deck2 and deck3.</p> <p>I also have an NSDictionary object that maps NSString objects to Card objects. I use the cards in deck1 to build this lookup table at the beginning of the game like this...</p> <pre><code>-(NSDictionary *)buildLookupTable { NSMutableDictionary *lookup = [[NSMutableDictionary alloc] init]; for (Card *card in self.cards) { NSString *lookupCode = [self buildCode:card]; [lookup setObject:card forKey:lookupCode]; } return lookup; } </code></pre> <p>I then pass the NSDictionary and the Decks to a layer object, but when I attempt to lookup a given Card based on a NSString, I get "-[CFString hash]: message sent to deallocated instance", but I can easily find the Card I'm looking for, not deallocated, in deck1 or deck2.</p> <p>The NSString I'm using as a key to retrieve the desired value isn't deallocated, nor is the NSDictionary itself. I have even iterated over the return from the NSDictionary object's allValues method, and none of those are deallocated either. </p> <p>What other deallocated objects could there be?</p> <p>Edit-version2: I've narrowed it down a bit.</p> <p>In the lookup code this works</p> <pre><code>NSString *key = @"4-0"; //(NSString *)sprite.userData; return [self.cardLookup objectForKey:key]; </code></pre> <p>but this doesn't</p> <pre><code>NSString *key = (NSString *)sprite.userData; // value is @"4-0" return [self.cardLookup objectForKey:key]; </code></pre> <p>In the debugger sprite.userData looks fine.</p> <p>sprite.userData is defined in the Card class buildSprite method as...</p> <pre><code>sprite.userData = [NSString stringWithFormat:@"%i-%i",self.x, self.y]; </code></pre> <p>It looks like calling copyWithZone on key doesn't work (like it would for any other NSString).</p>
    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.
 

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