zzyzy
zzyzy

Reputation: 983

NSDatePicker... CoreData storing the date range?

In my app, I'm currently using two textual NSDatePicker objects to designate a start & end date, respectively. The individual value keys have a corresponding Date attribute in my Core Data store.

Ideally, I'd like to go down to one graphical NSDatePicker object configured in NSRangeDateMode. Programmatically, I can retrieve this interval, via [myDatePicker timeInterval].

There is a discussion here about how it's impossible to use Cocoa bindings directly with timeInterval, but is anyone aware of a piece of recent OSX API magic that'll make this happen?

(A kludge would be along the lines of a separate NSNumber attribute in the CoreData store that would be set/get in a CD category addition to the parent NSManagedObject entity that would parallel the set/get on the primary time value attribute -- possibly via a separate NSNotification.)

Upvotes: 0

Views: 204

Answers (1)

Wil Shipley
Wil Shipley

Reputation: 9553

There’s no easy way to do this that I know of. What I’d probably do is make a subclass of NSDatePicker that had an observable endDateValue property that you synthesize yourself. Should be like 20-30 lines of code, the tricky part will be finding what you can subclass in NSDatePicker that will get called every time there’s a change, so you can call:

[self willChangeValueForKey:@“endDateValue”];
[self didChangeValueForKey:@“endDateValue”];

You won’t be able to bind to this easily in Interface Builder, either.

Another question is how do you want to model this range in the database? Do you want to separate dates? Or a date and a number of days? Or do you want to mash them together into a dictionary or a custom object? Whatever you choose to do at the database level, you can make your NSDatePicker subclass return it and accept it, so it’ll talk to the database directly (once hooked up in code).

Upvotes: 1

Related Questions