Saving application state

Discussion in 'iOS Programming' started by jsnuff1, Jul 29, 2008.

  1. jsnuff1 macrumors 6502a

    Joined:
    Oct 4, 2003
    Location:
    NY
    #1
    Im having a little trouble figureing out how to save simple instance variables to a file in order to save my application state.

    I have figured out how to read and write data with Archivers, but this requires objects to be sent to the data archiver via an Array.

    The only thing i need to do to save my application state is save two double instance variable and one boolean instance variable and them simply reinitialize them when the application is run again.

    How would i go about saving these double and boolean values with an archiver?
     
  2. jsnuff1 thread starter macrumors 6502a

    Joined:
    Oct 4, 2003
    Location:
    NY
    #2
    well i cheated and just converted the doubles and bool value into an NSString object and put those into an array and sent the array to the archiver.

    Just more work when i read the strings i need to convert them back to double and bool.

    Any better way to do this?
     
  3. Taum macrumors member

    Joined:
    Jul 28, 2008
    #3
  4. dgdosen macrumors 65816

    dgdosen

    Joined:
    Dec 13, 2003
    Location:
    Seattle
    #4
    That's what NSDecimalNumber and NSNumber is for!

    You just need to get used to NSDecimalNumber math. It's long-winded. That and I think it leaks.
     
  5. jehiah macrumors newbie

    Joined:
    Jul 12, 2008
    Location:
    NY
    #5
    you could use a sqlite database

    Another option is to save your application state in a sqlite database.

    I've found FMDB to be a good library for accessing sqlite databases. You can also check out the SQLiteBooks example application from apple for an example of that.
     
  6. Sbrocket macrumors 65816

    Sbrocket

    Joined:
    Jun 3, 2007
    Location:
    /dev/null
    #6
    Err, an sqlite database is overkill to store three variables. Use NSUserDefaults. As long as its a small amount of data, sqlite is way more work than you need.
     

Share This Page