While I do all my programming on the Mac and have built several apps, I’ve never really taken advantage of or learned much about plist files. I know some are XML text files, some are binary, they store preferences and settings, etc. etc. Beyond that, I don’t know much.
I am developing an app that I may actually want to put on the App store and I know I will need to use some plist files for stuff with that like saving settings and all - right? But before I even get there, I want to use a plist file to store the license key for the software that the user enters. But what plist to use? Do you use the plist in ~/library/preferences/com.company.appname?? Do you use info.plist inside the app package?
And then what classes do you use in Xojo for them. Unlike Windows where there’s a registry class (and I hate admitting I think I know more about the Windows registry than plists), I don’t see any plist classes in Xojo. So again, I’m looking for some guidance.
I know this is a bunch but I’m not exactly sure where to start other than searching Apple’s developer docs…
OK great. Thank you. I figured MacOSLib probably had some good stuff there. I just hadn’t pulled it up.
But what’s considered the best place to store a license key or other info you want to save? Right now I’ve just been using a text file for that stuff, but just wondering what most people use. In Windows, I’m going to store my license key and user info in the registry. On Mac I thought I’d use a plist that was already existing. Can I use the Info.plist file that is in the app package?
[quote=62976:@Joe Ranieri]They’re used in a lot of places on OS X just because they’re really convenient to create from C or Objective-C. There’s usually nothing saying you have to store your application’s data in a plist.
OK. Good to know.
[quote]You’ll probably want to use the CFPreferences wrapper in the macoslib project.
Excellent. Thank you.
[quote]Don’t write to your own app’s Info.plist. It’s full of problems, one of which is that it’ll break your application’s code signature.
OK. Can you create a different file in there? Or no - stay away completely from inside the package?
OK. That’s probably the place where it’s going. Since everyone has said it’s not necessary, I’m thinking of not changing since I have code that works and I’m talking about 3 lines of information in the file I want to write. If it’s not necessary, why add more work and more possibility of bugs!
Like others here are saying, you don’t have to use plist files, on Obj-C they’re very convenient as you can easily read or write out many core NSTypes. Quite a few of our apps use plist files, and I love the ability to crack them open in Xcode and edit them.
The plist file format is very flexible and tolerant, and if you’re building Mac only and don’t mind using NSTypes, I’d recommend it. Otherwise feel free to use whatever you want.
If you want to store preference files, in the Apple preferred way, then you should use NSUserDefaults. Apple have long advised against manually maintaining a preferences file in the preferences folder. If you don’t use NSUserDefaults, you should store your prefs in the Application Support folder. Basically the preferences folder is for backwards compatibility, future versions of OS X may not have this folder!
I once talked with the CoreFoundation engineer who was in charge of CFPreferences at the time and he suggested that they might move the actual preference storage somewhere else and just leave the preferences folder for old applications to muck with. Not an official statement, mind you, but just sort of a reinforcement of “don’t do this”.
Ironically Mavericks, is the first version where I’ve seen anything to this effect. If you use NSUserDefaults and delete the .plist file in the preferences folder, it corrupts the preferences! If you don’t use NSUserDefaults, it works as expected!
So you should or should not use NSUserDefaults? And as I’m not very schooled in Obj-C (I stopped learning it to focus on learning Xojo), is NSUserDefaults a function that can be used with declares? Is it available in MBS or MacOSLib?