Monday, November 20, 2017

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

ProGrammer
Member
Registered: 2016-12-16
Posts: 16

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:

Applescript:

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 01:56:27 am)


Filed under: applescript, data, xcode

Offline

 

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

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5177

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 <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)