Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Jun 21, 2009, 07:56 AM   #1
macrumors newbie
Join Date: Jun 2009
Location: East Tennessee
Core Data Date formatting issue

Hopefully someone can help me with this one. I have a contact management app that has date fields for "Last Contact date" and "Next Contact Date". I created a search predicate that would search on next contact date and display only the records for that date. It worked great until I decided I needed to create a user preference so the next contact date would automatically be some date in the futrure. I created a subclass of NSManaged object and put my code there.

Everything works except the date it writes to the database looks like this: >name="nextcontact" type="date">268045271.25241801142692565918<

For some reason my search predicate does not find the records with this format. Before I changed the date with my subclass the date field in the database looked like this: >266515200.00000000000000000000< (always containing the 00.00000000000000000000 string)
With this format the search predicate works fine.

My code to add to the date field looks like this:
- (void)awakeFromInsert {
int t;
t = [[NSUserDefaults stardardUserDefaults] integerForKey:@"nextContactDate"]; // gets # of days to add to date from user preferences
[self setValue:[NSDate dateWithTimeIntervalSinceNow: (3600*24*t)] forKey:@"nextContact"]; // sets the value of nextContact in a new record by adding 't'

The search predicate is quite simple and looks like this: nextContact = CAST($value "NSCalendarDate")

My question is how can I fomulate a date that will save as the second example above (or possibly change the predicate so it will work with the new date format).


Last edited by beaglboy; Jun 21, 2009 at 08:28 AM.
beaglboy is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Formatting Hard Drive - Core Storage RVijay007 OS X Mavericks (10.9) 3 Dec 17, 2013 10:35 PM
Date formatting in Numbers on Mac jootly Mac Applications and Mac App Store 6 Jul 27, 2013 12:28 PM
Having an issue passing data between views with Core Data. iJustinCabral iPhone/iPad Programming 0 Jul 15, 2013 09:50 PM
Formatting Excel Date Error RatHat Mac Applications and Mac App Store 2 Jun 28, 2013 09:44 PM
Saving data from custom tablecells core data luke3 iPhone/iPad Programming 0 Jul 14, 2012 06:09 PM

Forum Jump

All times are GMT -5. The time now is 08:58 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2015, MacRumors.com, LLC