デフォルトのサウンドがいくつかあり、ユーザーが必要に応じて他のサウンドを追加できる Mac OS X アプリを作成しようとしています。の配列にサウンドをロードしています-awakeFromNib
:
for (NSString *str in [PreferencesController beats]) {
resourcePath = [[NSBundle mainBundle] pathForSoundResource:str];
beat = [[NSSound alloc] initWithContentsOfFile:resourcePath byReference:YES];
[beat setLoops:YES];
[beat setName:str];
[beatsArray addObject:beat];
}
アプリがユーザーによって追加されたサウンドを配列に追加しようとするまで、すべてが正常に機能します。それは言います:*** -[NSURL initFileURLWithPath:]: nil string parameter
。ファイルの URL が見つからないと推測していますが、ユーザーが次のコードでファイルを選択すると、ファイルをアプリのディレクトリにコピーしています。
if ( [openDlg runModalForTypes:[NSArray arrayWithObjects:@"aif",@"aiff",@"mp3",@"wav",@"m4a",nil]] == NSOKButton)
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *dataPath = [[NSBundle mainBundle] bundlePath];
NSLog(@"Datapath is %@", dataPath);
NSLog(@"Selected Files : %@",[[openDlg URLs] objectAtIndex:0]);
[fileManager copyItemAtURL: [[openDlg URLs] objectAtIndex:0] toURL: [NSURL fileURLWithPath: [[NSBundle mainBundle] bundlePath]] error:&error];
NSLog(@"File copied");
NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:[PreferencesController beats]];
NSString *fileName = [[[openDlg URL] path] lastPathComponent];
NSArray *fileNameArray = [fileName componentsSeparatedByString:@"."];
[newArray addObject:[fileNameArray objectAtIndex:0]];
NSLog(@"%@",newArray);
[PreferencesController setBeats:newArray];
[self awakeFromNib];
[_tableView reloadData];
}
このコードの何が問題になっていますか?