Re: Should I use NSDocument, NSUserDefaults or something else
Re: Should I use NSDocument, NSUserDefaults or something else
- Subject: Re: Should I use NSDocument, NSUserDefaults or something else
- From: Mark Munz <email@hidden>
- Date: Thu, 30 Sep 2010 12:31:35 -0700
I think you can use NSUserDefaults just fine.
For the exposure example, you might do something like register a
default value for "exposure" category.
First check for the camera specific key ("QI1438.exposure"), if result
is nil, grab the general category value.
You could wrap that in a single method that took a category &
cameraID. It could build the camera specific key, check it, and if
nil, return the category value.
Mark
On Thu, Sep 30, 2010 at 4:42 AM, Jonny Taylor <email@hidden> wrote:
> Thankyou for peoples patience with my recent very basic conceptual cocoa questions. I have another where I am trying to understand the best way of handling some persistent data storage.
>
> My app is a workstation for a type of microscope, which from the point of view of the software consists of several different video cameras and some other devices controlled over USB. Each camera has associated settings (e.g. exposure) that I want to persist between app launches. I am not sure what the best way is of storing this information. There are multiple cameras involved, with each camera having quite a distinct role, so I would like to tie the settings to individual camera serial numbers.
>
> I had a look into NSUserDefaults but that doesn't sound quite ideal. As far as I can see (and I may be missing something) it is not inherently designed for hierarchical data storage. If I wanted to store, say, QI1438.exposure and PS1451.exposure as separate (flat) keys, then I don't think there would be a way of specifying a default value for the generalized key "exposure" in registerDefaults (regardless of the camera serial number). It could also be argued that these settings are not really "user preferences", particularly since one could imagine having a different bank of settings for different experiments.
>
> This made me think that an NSDocument might be a more appropriate solution (different document for each experiment, storing a hierarchical dictionary of key/value pairs but implementing my own handling of defaults for missing keys, etc). However this class is understandably a very complex class and I'm finding it hard to drill down to the details of what I would need to do in order to implement this pretty basic functionality - particularly since in some ways it would be a non-standard use of the class, in that the "document" was not associated with one single window, etc. Can anybody point me towards some example code that uses an NSDocument for this sort of application?
>
> Any advice people have on which of these solutions (or indeed a third one...) I should be using would be very welcome.
>
> Cheers
> Jonny_______________________________________________
>
> 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
>
--
Mark Munz
unmarked software
http://www.unmarked.com/
_______________________________________________
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