• 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: User Defaults
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: User Defaults


  • Subject: Re: User Defaults
  • From: Laurence Harris <email@hidden>
  • Date: Mon, 30 Apr 2007 19:17:19 -0400


On Apr 30, 2007, at 6:53 PM, Roland Silver wrote:

OK, Chris; here's an example of what I'm trying to do.

My program has two menu items, call them "File..." and "File Again".
If the user chooses the former, he gets a window/panel allowing him to select the file the app works on. If he chooses the latter, the app works on the last file he selected.

"File..." and "File Again" are not standard menu command items. Why aren't you using Open... and Open Recent for these?


So, in the former case, I save the file path string in [NSUserDefaults standardUserDefaults], with key @"inFilePath", say.
In the latter case, I retrieve the file path string in [NSUserDefaults standardUserDefaults].

How are you saving and retrieving?

So the set of user defaults must persist between one invocation of the app to another, presumably stored in some file, somewhere. That file doesn't appear to be the project's Info.plist, because there's no occurrence of the string "inFilePath" there.

Nothing the user does should ever result in any changes to anything in your bundle. In fact, the user may not have sufficient access to do that. Even if he does, such an approach would not produce the expected result if multiple users use your application on the same Mac from different user accounts.


So where is it stashed? And do I have to do something to stash it (and retrieve it when my app begins execution), or does that happen automatically?

This is a Cocoa question. You should use the standard preferences functions provided by Cocoa (which I don't know since I use Carbon) and not worry about where the information is stored. The system takes care of all that for you. What you're really wanting to know is how to store and retrieve values from your preferences, which is a coding question that has nothing to do with Xcode. The cocoa-dev list is for those kinds of questions.


Larry


Although reading "User Defaults Programming Topics" should enlighten me, I'm unable to form a mental picture of what's going on from reading it.
---------------------------------------------------------------


On Apr 30, 2007, at 11:34 AM, Chris Hanson wrote:

On Apr 30, 2007, at 8:44 AM, Roland Silver wrote:

Starting from a project's xcodeproj file, how do I get to the place in the project itself where the plist is specified (the plist, that is, where I stash my own preferences)?
For instance, for my project called "markovx", I'd expect there to be a path <~/Library/Preferences/ com.yourcompany.markovx.plist> (but there isn't), and for there to be -- SOMEWHERE WITHIN THE PROJECT ITSELF -- a specification of that path.


My question is, how do I get to see that path specification?

What is it that you're really trying to accomplish? It sounds like you're going about it in an overly-complex route. If you tell us what it is that you're actually trying to do, there may be a straightforward way to do it that you may not have considered.


There is no such path ever specified anywhere. The path is generated at runtime by the underlying frameworks that implement the preferences mechanism. It's typically generated from an application's bundle identifier, though there are ways you can request that the APIs use a different identifier. Also, when you say "the plist" and you're talking about an application, it's generally expects that you're talking about its Info.plist file, not its user defaults (preferences) database.

An application's bundle identifier is specified in its Info.plist. At build time, the target that builds that application has a build setting that Xcode's build system uses to find a "prototype" Info.plist file. Xcode's build system processes this file, potentially running the C preprocessor on it and also performing build setting substitution, and makes the result of this processing the built application's Info.plist.

Note that because the location of the prototype Info.plist file is specified by a build setting, it may not be specified or completely specified by the target itself. It might be inherited from the project that contains the target, it might be specified in an xcconfig file, it might be the result of evaluating other build settings, and so on. If a target does not directly specify its Info.plist file, the only way to have perfect knowledge of what file the Xcode build system will use is to be the Xcode build system.

-- Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >project's plist (From: Roland Silver <email@hidden>)
 >Re: project's plist (From: Chris Hanson <email@hidden>)
 >User Defaults (From: Roland Silver <email@hidden>)

  • Prev by Date: Re: Prefix/precompiled header has no effect
  • Next by Date: Re: Xcode does not save state of split windows
  • Previous by thread: User Defaults
  • Next by thread: Re: User Defaults
  • Index(es):
    • Date
    • Thread