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

jsnuff1

macrumors 6502a
Original poster
Oct 4, 2003
726
333
NY
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?
 

jsnuff1

macrumors 6502a
Original poster
Oct 4, 2003
726
333
NY
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?
 

dgdosen

macrumors 68030
Dec 13, 2003
2,742
1,381
Seattle
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.
 

jehiah

macrumors newbie
Jul 12, 2008
3
0
NY
you could use a sqlite database

Im having a little trouble figureing out how to save simple instance variables to a file in order to save my application state.

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.
 

Sbrocket

macrumors 65816
Jun 3, 2007
1,250
0
/dev/null
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.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.