繁体   English   中英

为什么我得到这个:_cfurl:无法识别的选择器

[英]Why am I getting this: _cfurl: unrecognized selector

我的初始化是这样开始的:

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

当我们到达最后一行时,它会抛出这个:

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'

是的,调试起来有点不紧凑。

就在我得到转储之前,theFirstNoise 包含预期的(某种)数据。 (它的描述方法打印出一个奇怪的形式,但我被告知这是正常的。)

在我的脑海中,看起来theFirstNoise实际上是NSPathStore2NSString的私有子类)而不是NSURL

编辑: NSPathStore2对象将包含文件路径。 如果您需要将这些转换为NSURL ,您可以简单地将它们传递给+[NSURL fileURLWithPath:]

这一行:

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

是问题所在: [sounds allKeys] 返回键的 NSArray,而 objectAtIndex: 因此返回的是 NSString,而不是 URL。 我希望编译器会更有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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