简体   繁体   中英

Why am I getting this: _cfurl: unrecognized selector

My init starts like this:

- (id) init {
    [super init];
    sounds = makeDictFromArrayOfURLs(getNoiseFileURLs());
    [sounds retain];
    NSURL *theFirstNoise = [[sounds allKeys] objectAtIndex:0];
    CFURLRef uref = (CFURLRef)theFirstNoise;
    OSStatus ret = AudioServicesCreateSystemSoundID(uref, &chosenNoise);

When we get to that last line, it throws this:

2011-06-09 23:19:18.744 SuperTimer[94516:207] -[NSPathStore2 _cfurl]: unrecognized selector sent to instance 0x940cfb0
2011-06-09 23:19:18.746 SuperTimer[94516:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSPathStore2 _cfurl]: unrecognized selector sent to instance 0x940cfb0'

Yeah, it's a bit uncompact for debugging.

Just before I get the dump, theFirstNoise contains the expected (sort of) data. (It's description method prints a weird form, but I am informed that's normal.)

Off the top of my head, it looks like theFirstNoise is actually an NSPathStore2 (a private subclass of NSString ) instead of an NSURL .

Edit: NSPathStore2 objects will contain file paths. If you need to turn these into NSURL s, you can simply pass them to +[NSURL fileURLWithPath:] .

This line:

NSURL *theFirstNoise = [[sounds allKeys] objectAtIndex:0];

is the problem: [sounds allKeys] returns an NSArray of keys, and objectAtIndex: therefore is returning an NSString, and not the URL. I wish the compiler would have been a little more helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM