0

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

- (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 包含预期的(某种)数据。(它的描述方法打印出一个奇怪的形式,但我被告知这是正常的。)

4

2 回答 2

3

在我的脑海中,它看起来theFirstNoise实际上是一个NSPathStore2(的私有子类NSString)而不是一个NSURL.

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

于 2011-06-10T04:04:52.453 回答
1

这一行:

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

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

于 2011-06-10T04:52:12.960 回答