Note that there are some explanatory texts on larger screens.

plurals
  1. POUnrecognised selector crash within [NSDictionary valueForKey:]
    primarykey
    data
    text
    <p>I'm occasionally getting this crash, which is very hard to reproduce:</p> <pre><code>0 CoreFoundation 0x39ff73e2 __exceptionPreprocess + 158 1 libobjc.A.dylib 0x3905095e objc_exception_throw + 26 2 CoreFoundation 0x39ffaf2c -[NSObject(NSObject) doesNotRecognizeSelector:] + 180 3 CoreFoundation 0x39ff9648 ___forwarding___ + 388 4 CoreFoundation 0x39f51204 _CF_forwarding_prep_0 + 20 5 Foundation 0x32914bec -[NSDictionary(NSKeyValueCoding) valueForKey:] + 28 6 MyAppName 0x00032112 -[myViewController stopPlayersWithVolume:] (myViewController.m:151) </code></pre> <p>From this code:</p> <pre><code>- (void)stopPlayersWithVolume:(double)volume { for (NSString *file in players) { AVAudioPlayer *player = [players valueForKey:file]; if (player.volume == volume || volume == 0) [player stop]; } } </code></pre> <p><code>players</code> is an <code>NSMutableDictionary</code> property, accessed without <code>self.</code> because I don't believe it's needed with ARC. The keys are filenames (e.g. "mysound.mp3") and the values are <code>AVAudioPlayer</code> objects.</p> <p>Is the stack trace saying that the parameter <code>file</code> I'm passing to <code>[NSMutableDictionary valueForKey]</code> is not actually an <code>NSString</code>, and hence the unrecognised selector? It is always an <code>NSString</code> in the debugger, as you'd expect as it comes from a fast enumeration through the dictionary, but the crash never occurs in the debugger.</p> <p>My only thought is that there's a threading issue corrupting the dictionary. The code above is being fired by an NSTimer but that's just a message via the run loop, not a separate thread, so I believe there should be no need to worry about cross-thread access?</p> <p>Any suggestions appreciated. Sorry to just dump this out but I'm stuck.</p> <p><strong>Edit:</strong></p> <p>The players dictionary is allocated in <code>viewDidLoad</code> thus:</p> <pre><code>players = [[NSMutableDictionary alloc] init]; </code></pre> <p>And declared as follows:</p> <pre><code>@property (retain, nonatomic) NSMutableDictionary *players; </code></pre> <p>And synthesised as follows:</p> <pre><code>@synthesize players; </code></pre>
    singulars
    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.
 

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