Execute code only for first time the app starts..

Discussion in 'iOS Programming' started by AbhishekApple, Oct 29, 2010.

  1. AbhishekApple macrumors member

    Joined:
    Aug 5, 2010
    #1
    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..
     
  2. AbhishekApple thread starter macrumors member

    Joined:
    Aug 5, 2010
    #2
    Is this possible through programming or i will have to create filename.plist
     
  3. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #3
    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).
     
  4. plinden macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #4
    Seems to me this would be a candidate for NSUserDefaults rather than rolling your own code.
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    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
    }
    
     
  6. AbhishekApple thread starter macrumors member

    Joined:
    Aug 5, 2010
    #6
    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...
     

Share This Page