Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Almost finished app, just need advice finalizing it.
-
Hey everyone. So I have an app that is basically ready but I have a few las things I want to polish first. They are listed below. I’d appreciate any advice on how to accomplish the following:
-
I have two views/sheets in this app. The first one sets up settings for the second one. How can I make it so that the first sheet only appears the first time the app is opened? Like when the user closes and reppens the app, the first sheet will not appear, it goes straight to the second. Is this something done in pythonista or xcode.
-
In relation to the first question, how do I make the settings the user changes in the first sheet stay permanent dor everytime they open the app, even after closing it? Like if they change the color of a square to red, how can I “save” that so that everytime the user opens the app, the square is red?
Thank you in advance!!
-
-
@procryon I often use a dictionnary to store the settings of my apps.
I save the settings in keychainWhen I start my app, I check if the keychain is present:
settings_str = keychain.get_password(script_name,'settings') if settings_str: settings = ast.literal_eval(settings_str) # convert str -> dict else: # Init settings settings = {'setting1':'value1','setting2':'value2',...} # Save settings into keychain settings_str = str(settings) # convert dict -> str settings_str = keychain.set_password(script_name,'settings',settings_str)
-
-
@pastorhudson I even support newly added settings or old removed settings:
# Eventual remove unused settings #settings_del = ['Serveur','Utilisateur','Mot de passe','Répertoire'] settings_del = [] for setting_key in settings.keys(): if setting_key not in settings_init: # setting has been removed, store key to be removed settings_del.append(setting_key) for setting_key in settings_del: del settings[setting_key] # Eventual add new settings settings[setting_name] = 'value'
-
I'll add my vote for using a JSON file to save settings :) JSON maps nicely to Python lists/dicts, so I find it very convenient to use for this sort of thing. I wouldn't put it in the keychain unless the data is actually sensitive, simply because it seems like the wrong tool for the job. I don't know enough about Pythonista's keychain module and the iOS keychain in general to say if it would actually be bad, but personally I wouldn't want to test it out.
@cvp By the way, you can use
dict.pop(key, None)
to remove a key if it's in the dict, and do nothing if it's already missing. That way you can simplify your code to this:for key in settings_del: settings.pop(key, None)
Similarly, there's
dict.setdefault(key, value)
: ifkey
is already in the dict, it returns the existing value, otherwise it doesdict[key] = value
and returnsvalue
. That way you can write code likelanguage = settings.setdefault("language", "en-US")
, which gets the language from the settings and sets it to"en-US"
if missing. -
@dgelessus As with only two lines, get_services() and get_keychain(), you can get the data of keychain memory, I never shall store there sensitive data, without a real password protection. I only wanted to store my parameters without using a file that the user could remove by accident.
About Python dictionary, I recognize I don't know a lot about it.Thanks for the info.