[英]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.就在我得到转储之前,theFirstNoise 包含预期的(某种)数据。 (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
.在我的脑海中,看起来theFirstNoise
实际上是NSPathStore2
( NSString
的私有子类)而不是NSURL
。
Edit: NSPathStore2
objects will contain file paths.编辑: NSPathStore2
对象将包含文件路径。 If you need to turn these into NSURL
s, you can simply pass them to +[NSURL fileURLWithPath:]
.如果您需要将这些转换为NSURL
,您可以简单地将它们传递给+[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.是问题所在: [sounds allKeys] 返回键的 NSArray,而 objectAtIndex: 因此返回的是 NSString,而不是 URL。 I wish the compiler would have been a little more helpful.我希望编译器会更有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.