• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Displaying date in Core Data application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Displaying date in Core Data application


  • Subject: Re: Displaying date in Core Data application
  • From: mmalcolm crawford <email@hidden>
  • Date: Tue, 4 Apr 2006 13:35:19 -0700


On Apr 4, 2006, at 1:42 AM, Wayne Pascoe wrote:

I have a core data application that uses an NSDate field.

This isn't really a Core Data question, it's generic to any application...

I am displaying this field in an NSTableColumn. When the application runs, the full date, including time is displayed.
What is the right way to change my NSTableColumn to just display the day, month and year?


See <http://developer.apple.com/documentation/Cocoa/Conceptual/ DataFormatting/Articles/dfCells.html>.
With Mac OS X 10.4 and later, you are encouraged to use formatters with 10.4 behaviour rather than the formatters you get from IB (see <http://developer.apple.com/documentation/Cocoa/Conceptual/ DataFormatting/Articles/dfDateFormatting10_4.html>).


At the moment, I have a bit of a hack for this. I have used a custom class for the entity that contains the date, and added an awakeFromInsert method. This method. I have also added a String attribute to the entity named displayDate. In my awakeFromInsert method, I am setting the displayDate attribute as follows:
[self setValue:[NSDate date] forKey:@"date"];
[self setValue:[[NSDate date] descriptionWithCalendarFormat:@"%Y-%m- %d"
timeZone:nil
locale:nil] forKey:@"displayDate"];


I would strongly discourage this approach. Data presentation is a UI layer issue, not something the model objects should be concerned with.

I will also have to add a didChangeValueForKey:@"date" method somewhere to change the display date on updates.

This is an incorrect approach:
(a) You should not use the KVO change notification messages independently (a 'didChange...' should only ever follow a 'willChange...');
(b) KVO provides a mechanism for denoting dependencies, see <http:// developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/ Concepts/DependentKeys.html>.


mmalc


_______________________________________________ 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
References: 
 >Displaying date in Core Data application (From: Wayne Pascoe <email@hidden>)

  • Prev by Date: Bindings question for core data application
  • Next by Date: Re: Core Data: adding a child data element, saving... 'Selector Not Recognized'
  • Previous by thread: Re: Displaying date in Core Data application
  • Next by thread: NSProgressIndicator, runModalForWindow, detachNewThreadSelector -> Not good...
  • Index(es):
    • Date
    • Thread