• 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
Property in class mirrored to user defaults
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Property in class mirrored to user defaults


  • Subject: Property in class mirrored to user defaults
  • From: Jonathan Taylor <email@hidden>
  • Date: Mon, 12 Jun 2017 10:04:15 +0100

Hi all,

This feels like a very basic question, but one that I have not had any luck
searching for (maybe I am using the wrong terms?).

At the moment I have properties in a (singleton) class that are bound to UI
elements. At the moment they have the same automatic values every time the app
is launched, although the user can change them while it is running. What I
would like is for the user's previous choice to be remembered when the app is
next launched. Obviously this would seem to be a job for NSUserDefaults. I am
not sure quite what the right way to structure things is, though.

All the simple examples I have seen bind to NSUserDefaults and then if the
program actually wants to know what the value is, it simply accesses the values
directly on NSUserDefaults. I would prefer not to do that, though (see below).

What I ~think~ I would like is to still be able to access the values as
properties of my class. That seems to me like the natural way, and it would
seem odd to have two categories of value, some accessed through properties on
the class, and some accessed some other way via NSUserDefaults. However, if I
bind the UI elements to the shared user defaults object, is that not what will
happen? Or is there some way that I can "link" my class and the user defaults
object, so that the properties are saved in user defaults but I can still
access them in a fairly seamless way from my class? I do like the idea of
having the properties (and their types) explicitly declared as part of my
class, rather than being mysterious objects that only exist in the user
defaults.

Does anyone have any advice on how I can achieve this, or on how I should be
thinking about all this differently?
Thanks
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

  • Follow-Ups:
    • Re: Property in class mirrored to user defaults
      • From: Alex Zavatone <email@hidden>
    • Re: Property in class mirrored to user defaults
      • From: Charles Srstka <email@hidden>
  • Prev by Date: Re: Drawing a 5 Sided Star Shape
  • Next by Date: Re: Property in class mirrored to user defaults
  • Previous by thread: Re: Creating "Application Scripts" subfolder in sandboxed environment
  • Next by thread: Re: Property in class mirrored to user defaults
  • Index(es):
    • Date
    • Thread