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'

ええ、それはデバッグのために少しコンパクトではありません。

ダンプを取得する直前に、FirstNoiseには期待される(ある種の)データが含まれています。(descriptionメソッドは奇妙なフォームを出力しますが、それは正常であると通知されます。)

4

2 に答える 2

3

私の頭の上では、theFirstNoise実際にはの代わりにNSPathStore2(のプライベート サブクラス) のように見えます。NSStringNSURL

編集:NSPathStore2オブジェクトにはファイル パスが含まれます。これらを に変換する必要がある場合NSURLは、単純に に渡すことができます+[NSURL fileURLWithPath:]

于 2011-06-10T04:04:52.453 に答える
1

この行:

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

が問題です: [sounds allKeys] はキーの NSArray を返し、objectAtIndex: は URL ではなく NSString を返します。コンパイラがもう少し役に立てばよかったのに。

于 2011-06-10T04:52:12.960 に答える