Re: MVC design Q - remembering Core Data selections
Re: MVC design Q - remembering Core Data selections
- Subject: Re: MVC design Q - remembering Core Data selections
- From: Ron Fleckner <email@hidden>
- Date: Mon, 25 Jan 2010 21:05:28 +1100
On 25/01/2010, at 8:42 PM, Ken Tabb wrote:
On 25 Jan 2010, at 9:38, Tabb, Ken wrote:
Hi folks,
I have a Core Data app that needs to remember state of selected items
between launches.
The app's UI is a bit like iTunes (containers / playlists down the
side and contents show in a big tableview), except that there are 3
layers of containment, so rather than Playlists and Tracks, you could
think of it as Companies, Departments & Employees.
What I'd like is for each Company to remember the last selected
Department in it, and for each Department to remember the last
selected Employee in it. I'd like to remember this between launches.
To clarify, I'm not just wanting to remember which Company / Dept /
Employee the user was last looking at before they quit, but for each
Company & Department, what the last selected object within it was.
So in other words say the user clicks on "Apple", and then on the
"Upper Echelons" Department, and then "Steve Jobs". After this, the
user then clicks on a different company, say... Slate Computing
LLC...
and on some department and employee within it. The user then quits.
When the user relaunches, I'd like it to go straight to showing the
Slate Computing LLC + selected department + selected employee.
However, if the user clicks on Apple, I'd like it to remember that
they were last looking at its "Upper Echelons" department, and "Steve
Jobs" in particular.
The hack that I can think of to do this would be for each Company
entity to have a "selectedDept", and for each Department entity to
have a "selectedEmployee" relationship, but this kind of breaks
MVC...
other than it being easy to implement, the model shouldn't care what
the user was last looking at. Furthermore if I ever implement multi-
client access, then it can only remember (in the central data
repository) what 1 user was last looking at, so if Fred was last
using
the app and I launched it, it would start me up with Fred's last
selection if this is stored inside the model.
What is the preferred MVC design for implementing this kind of
functionality?
I could be barking up the wrong tree here but I'm thinking I should
override the Company & Department array controllers, so that each
time
their selection changes, I get the managed object IDs for the new
selection, and write it out to a preference list (or a separate per-
user persistent store), and reading from this when the user selects
something else, so we know which child item to select by default for
them. Would this break when the managed objects go from being
temporary (i.e. new) to permanent (i.e. saved) though? Or should I
only write the file / 2nd store when the app is quitting (after
everything that's staying has been committed)?
Hope I've stated my problem well enough - if anything needs
clarification let me know.
Thanks in advance for any help you can give,
Ken
Hi Ken,
I think this would be a job for user defaults. So at app shut down,
I'd just intervene at that point and write the current selection
details to user defaults. No need to futz with your model. Of
course, you'd only then have the selection for one of the companies,
but that is sort of what Mail does. It remembers the last selected
email and the last selected mailbox, but no other.
Ron
_______________________________________________
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