[英]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
實際上是NSPathStore2
( NSString
的私有子類)而不是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.