• 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: Core Data dynamic attributes and fetching
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data dynamic attributes and fetching


  • Subject: Re: Core Data dynamic attributes and fetching
  • From: Ben <email@hidden>
  • Date: Sun, 25 May 2008 07:33:35 +0100


On 24 May 2008, at 21:47, Ben Trumbull wrote:

At 2:56 AM -0700 5/24/08, email@hidden wrote:
I have a core data object graph using an SQLite store where several entities have an attribute containing a date (eg, birthDate). This is stored as a date type.

I am currently implementing an NSPredicateEditor for building smart groups. Each smart group simply saves this predicate to an attribute and then fetches using that.

The problem is that I want to offer to filter by ('days since birth' == 7), as well as (birthDate == 01/01/01). This is where I have hit a
wall. I can't set a dynamic transient property for daysSinceBirth as
these can't be used in fetch requests, and I can't convert the number
of days to an absolute date as this loses the dynamic-calculation part
of the number.

This is the part I'm not following. Why don't you transform:

'days since birth' == 7 into 'birthDate == $x' where $x = 'currentDate - 7 days'

Generally speaking, you always want to work with absolute time (seconds since reference date, UTC) in the database. The only place you should use calendar, human legible dates, or time zones is with entities like users' Preferences or user's active Session. Obviously your UI layer needs to represent dates in a way your customers will appreciate.

Calendar properties are political and historical issues as well as geographically relative. Calendars make the Unicode spec look like riding a big wheel. They are generally not useful to store in the database.

Nothing stops you from using the NSPredicateEditor with 'fake' properties and then grabbing the predicate it makes and transforming it into another one. Pulling apart an NSPredicate tree is tedious, but not hard.
--


-Ben

I didn't want to transform and store an absolute date, as the predicate should always show 7 days ago, no matter what the date today. I have got an example working similarly to how you suggest though:


It sets a constant value for the left expression and the number of seconds to adjust by in the right expression. This is saved to the store exactly as-is. When it is retrieved, that constant key is detected and the subpredicate replaced with a key path and absolute date suitable for fetching with.

Thankfully, this app is *highly* region-specific, so calendar differences are of little account.

Thanks for the advice though. It's not as pretty as I hoped, but it seems to work quite well.

Ben.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >re: Core Data dynamic attributes and fetching (From: Ben Trumbull <email@hidden>)

  • Prev by Date: Re: How to Delay, Wait, Pause...
  • Next by Date: Re: How to Delay, Wait, Pause...
  • Previous by thread: re: Core Data dynamic attributes and fetching
  • Next by thread: Quit iTunes
  • Index(es):
    • Date
    • Thread