file - Adding data given by the user to an array - Objective-C -


i'm trying create mac os x app there default sound , user can add others if wants. i'm loading sounds array in -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]; } 

everything works fine until app tries add array sound added user. says : *** -[nsurl initfileurlwithpath:]: nil string parameter. i'm guessing can't find url of file i'm copying file app's directory when user selects following code :

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 %@", 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]; } 

what's wrong code?

looks you're trying copy file folder because you're using bundle path destination url. destination url needs specify full path including destination file name.

try logging error when file copied:

nslog(@"file copied error: %@", error); 

this line contains error:

[filemanager copyitematurl: [[opendlg urls] objectatindex:0] tourl: [nsurl fileurlwithpath: [[nsbundle mainbundle] bundlepath]] error:&error]; 

specifically, problem destination url folder:

[[nsbundle mainbundle] bundlepath] 

it should like:

[[[nsbundle mainbundle] bundlepath] stringbyappendingstring:[[[[opendlg urls] objectatindex:0] path] lastpathcomponent]; 

then, once have working, @abizern says in comments, saving bundle bad idea (it's part of app). once have working, should choose better location save sounds (like support document folder app, programmatically path application support folder)


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -