Sunday, July 15, 2018

#1 2017-11-05 12:51:03 am

Registered: 2016-12-16
Posts: 23

Best way for data to persist between app launches

As the next big step in developing my AppleScript Xcode application, I would like to implement the best solution for data persistence between launches.
The application contains a text field for a name (type: string), a checkbox (type: boolean) and a Popup Button from which the user can select a string value. These should then be saved and usable by the application right away (in the same run). Once the user exists, the saved data should persist (probably either NSUserDefaults or .plist file etc.) and be recalled during the next run so that the user does not need to go through the same 'setup' steps again.

Here is the catch, my application will be portable (i.e. run from a USB drive, never installed locally), and used between different Macs. From my understanding of NSUserDefaults, I gather it is unwise to utilise NSUserDefaults as these are stored on the local system, not the USB stick, correct?

As mentioned, I have my Textbox, Checkbox, Popup Button and a 'Save' button dragged onto my MainMenu.xib layout and now need to work on the saving button's action:


on saveBtn_(sender)
set nameToSave to stringValue() of nameTextBox as text --> Contents of TextField
set cBoxToSave to state of checkBox as boolean --> Value of CheckBox
set popupBtnToSave to titleOfSelectedItem() of popupBtn as text --> Selected Popup Item

log nameToSave
log cBoxToSave
log popupBtnToSave
end saveBtn_

I noticed that clicking on the text box and looking at the Bindings Inspector, it is possible to Bind the value to NSUserDefaults or, for example, "Application" - which sounds like the right thing to do as data might persist with the app, rather than the local user defaults on the computer...

Never having worked with persistent data in Xcode (or AS), I am a little lost as to how to solve this, .plist files seem the way to go but rather clunky compared to the potential that the Bindings Inspector may hold, if my understanding of it is correct that is.

I would really appreciate any help to get me started on this.

Last edited by ProGrammer (2017-11-05 12:56:27 am)

Filed under: applescript, data, xcode



#2 2017-11-05 04:54:22 am

Shane Stanley
From:: Australia
Registered: 2002-12-07
Posts: 5404

Re: Best way for data to persist between app launches

NSUserDefaults can only be used for saving per-user -- bindings don't change that. if you want to save anywhere else, you will have to do it all yourself.

Shane Stanley <>



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)