Home > Tips > Core Data Default Dates in Data Model
Core Data Default Dates in Data Model
Posted on Friday, July 10, 2009 by android apps market for tablests
I'm leaving this blog entry, but do not use this tip - there is a flaw in it
When creating a managed object model using Xcode's Data Model Editor, I knew that there was a way to specify a default value for a date attribute that would cause it to default to the current date and time. It's one of those things I need to do about twice a year and can never, ever remember how it's done. Apple's documentation didn't yield an answer (it might be in there, but it's not easy to find). Yes, you can create a custom subclass of NSManagedObject and set the value in awakeFromInsert:, but for those situations where you don't want to subclass, or don't feel like it, I knew there was a way and it was frustrating me that I couldn't remember it or find it.
Thanks to Twitter, I got the answer, and it's a cooler answer than I remembered. The Default field for date attributes will interpret natural language strings put in quotes. It appears to be that anything that NSDate's natural language parser can handle, the date attribute's default field can handle. "Tomorrow", "Today", "Now", "Yesteday at Breakfast".
via Shane Crawford
When creating a managed object model using Xcode's Data Model Editor, I knew that there was a way to specify a default value for a date attribute that would cause it to default to the current date and time. It's one of those things I need to do about twice a year and can never, ever remember how it's done. Apple's documentation didn't yield an answer (it might be in there, but it's not easy to find). Yes, you can create a custom subclass of NSManagedObject and set the value in awakeFromInsert:, but for those situations where you don't want to subclass, or don't feel like it, I knew there was a way and it was frustrating me that I couldn't remember it or find it.
Thanks to Twitter, I got the answer, and it's a cooler answer than I remembered. The Default field for date attributes will interpret natural language strings put in quotes. It appears to be that anything that NSDate's natural language parser can handle, the date attribute's default field can handle. "Tomorrow", "Today", "Now", "Yesteday at Breakfast".
WHOAH: After a user comment alerted me to this, I tested it out and sure enough, the natural language string entered into the default field is actually determined at compile time, not at runtime, so 'today' will always result in the same date. Do not use this technique!
via Shane Crawford
Category Article Core Data, Other blogs, Tips
Powered by Blogger.
Blog Archive
-
▼
2009
(496)
-
▼
July
(61)
- We're Listening
- We're Listening
- The Iterative Web App: Links Got Shorter and Smarter
- The Iterative Web App: Links Got Shorter and Smarter
- DP aka Dataran Pahlawan Malacca.
- The Most Reliable
- Google Latitude. Now for iPhone.
- Google Latitude. Now for iPhone.
- Interesting Contrast
- Waving the Red Flag
- Microsoft's Ads Redux
- Layers of fun in Google Maps for mobile 3.2
- Layers of fun in Google Maps for mobile 3.2
- August 14 Workshop Update
- To VBO or Not to VBO...
- Improved Blender Export
- Refactoring Nav from Chapter 9
- Voyager Class Mixmaster
- Fixed & Improved Blender Export Script
- How MJ Died..
- A Little Ego Boost for a Friday
- WWDC 2009 Videos Available for Purchase
- Beginning iPhone 3 Development is Available
- Gah! Up is Down! Right is Wrong! Make it Stop!
- First Post
- Search with My Location for iPhone 3.0. And All t...
- Search with My Location for iPhone 3.0. And All t...
- Browse a collection of experts' favorite places us...
- Browse a collection of experts' favorite places us...
- New Device Rules
- Updating Project Hint
- Google Voice for Android and BlackBerry
- Google Voice for Android and BlackBerry
- Detail Editor Update: To Many Relationships
- Generic Detail Editor Update
- August 14 Workshop
- A Category on NSDate
- unusual business ideas that work Gadget
- Core Data Default Dates in Data Model
- A Kick-Ass Objective-C Programmer is a Kick-Ass C ...
- TinyPlayground Gadget
- Google Product Search for mobile now available for...
- Google Product Search for mobile now available for...
- Travelzoo UK Deals
- In Search of a Better Way: Editable Detail Views
- The Perils of Helping Others
- Core Plot
- More on Teaching
- An IPhone App Setback
- Oh, Good, Here Comes the Justice Department
- Windows Mobile: World Domination is In Sight!
- Core Data Navigation-Based Application
- iPhone Simulator Application Creator
- Wireless Carriers the Great Train Robbers of this ...
- An Exercise in Blatant Bias
- Core Data - Inserting a New Managed Object
- Google Search results optimized for feature phones...
- Google Search results optimized for feature phones...
- What, Me Teach?
- Mint Apps Promo Day is Today!
- Core Data - Determining if a Managed Object is New
-
▼
July
(61)