簡體   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