Re: Core data "now"
Re: Core data "now"
- Subject: Re: Core data "now"
- From: Matt Neuburg <email@hidden>
- Date: Mon, 06 Nov 2006 12:25:31 -0800
- Thread-topic: Core data "now"
On Mon, 6 Nov 2006 10:09:51 -0800, Matthew Weinstein <email@hidden>
said:
>Dear cocoa-xperts,
>I have an app I'm working on which uses core data, and I created the
>interface using the drag and drop from the core data model and then
>tweaking. Here's the problem: I have a date field and I want it to
>default to "now" whenever I hit add. So I thought what I'd do is
>have an action in my document which is triggered by the add button so
>that it sends an add: to the array controller; fills in @"Now" in my
>date field. Now that works, in terms of filling in the current date
>(though not time) in the NSTextField, but it doesn't actually update
>the database?
You're coming at this backwards. If "now" is the default value of the date
every time a managed object of this entity type is created, then implement
awakeFromInsert in your managed object subclass so that every newly created
object will simply initialize itself appropriately. Here is code from my
Diary application, which does precisely what you describe:
- (void)awakeFromInsert {
[super awakeFromInsert];
[self setValue: [NSDate date] forKey: @"date"];
}
Ta-daa! Feel free to download and examine the Diary source code; it is
intended as an elementary example of a Core Data app. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden