views:

82

answers:

3

I am new at Core Data, and it seems like it is a great way to manage the data store. However I am also very memory-conscious due to the fact that the iPhone doesn't have that much of it. I was a little surprised to see that the data types are so limited - eg. there is a Date type which includes also the time, but no Date type for just the date! All the time information takes up precious bytes of memory, if I just wanted an attribute with the date (e.g. 2/15/2010 rather than 2/15/2010 02:34:48), how could I do this? Is it possible?

A: 

Why don't u just save the date As a string and then use NSDate formatter to convert it back whenever u need to use it...

Daniel
+3  A: 

If you really think this will be a memory issue, store an NSNumber attribute for the Foundation double type NSTimeInterval, the value for which is derived from NSDate methods that measure the number of seconds since the epoch.

You'll trade memory savings for a performance hit, especially if you have to do a lot of conversion between the time interval's object representation and NSDate objects, but that's one option.

Another is to just use NSDate and see if you actually run into memory issues.

My suspicion is that you won't. If you do all the Core Data tricks that Apple recommends, you'll be faulting data, among other things. What this means is that your app will do as little actual data retrieval as necessary, until the app actually does need the data.

Alex Reynolds
+1  A: 

Dates are stored as seconds since epoch in the database and there is no concept of a "date" without hours. However I would be VERY surprised if this difference is going to impact your memory consumption as Core Data is just storing a double in the database.

Dates are never a memory issue, they simply are not big enough.

Marcus S. Zarra