Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AbhishekApple

macrumors member
Original poster
Aug 5, 2010
86
0
I want to Execute code only for first time the app starts...so that this code or file should not execute when user restarts the app....

Actually i want to store array in a file system of iphone. This array is editable,

Code:
Viewdidload(){
NSMutableArray *countriesToLiveInArray = [NSMutableArray arrayWithObjects:@"Iceland", @"Greenland", @"Switzerland", @"Norway", @"New Zealand", @"Greece", @"Italy", @"Ireland", nil];

code to : Save array to file abc

reload data from saved file abc
}

button_editclick{
Save array to file abc

reload data from saved file abc
}


if user edits the record i will save the edited array to file but if user restarts the app it will again reload the static array and will erase the edited record...

Plz suggest on this..
 
Just check the filesystem to see if the app has already saved the file. If not, then it's the first time (or the user deleted and reinstalled the app).
 
Seems to me this would be a candidate for NSUserDefaults rather than rolling your own code.
 
Here's the basic logic of what you want.
New is hilited in blue. Remove with line through it.
Code:
Viewdidload(){
[COLOR="Blue"]if saved file abc doesn't exist
{[/COLOR]
  NSMutableArray *countriesToLiveInArray = [NSMutableArray arrayWithObjects:@"Iceland", @"Greenland", @"Switzerland", @"Norway", @"New Zealand", @"Greece", @"Italy", @"Ireland", nil];

  code to : Save array to file abc
[COLOR="blue"]}[/COLOR]

reload data from saved file abc
}

button_editclick{
[s]Save array to file abc[/s]

reload data from saved file abc
}
 
thnkx for the reply guys....

i did that through plist....

the task was to keep the static user details on iphone (app), which gets loaded when user starts the app...User can also edit the user details which should get stored back to the file..

so during apploading i initialized an array with the file content and while terminating i saved back to the file...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.