I am trying to add arrays,dictionaries via NSUserdefaults.
The physical path is rootOfMyApplication/Library/Preferences/bundleidentifier.appName.plist where I can see data that I stored via NSUserDefaults while testing on simulator.
Suppose I give simulator hash folder to a friend without source code, will it be possible for him to identify the keys that I have used while storing in NSUserdefaults?
There are other keys in the plist ,How can we differentiate between the ones that are stored via NSuserdefaults?
My experience looking at the NSUserDefaults plist file shows that keys that start with the following are from Apple:
Apple...
NS...
Web...
As long as you avoid those prefixes you should be able to find all of the app keys.
I always try to use a specific prefix to my keys to be safe but you don't have to.
Related
I am taking development courses for ios and I was wondering if I wanted to create a translation app would i use a array list to do so? As example code is:-
var dictionary = [“talofa”: “hello’, “faafetai”: “thank you”]
print(dictionary[“talofa”])
it shows up in the logs as “hello” but there has to be an easier way to do translations otherwise I would be fitting a whole language in a array list?
I also read online that people have been using third party services like google to make a translation app but my language is not on google (Hawaiian) what do I do?
First of all, what you are using in your example, in swift/objc it is called a dictionary.
Secondly, for such a huge amount of data, I recommend you use some sort of persistent storage. You can use plain text to store the dictionary (like creating a .plist file), but being iOS I would recommend setting up coredata.
CoreData will allow you to store the information on the device, and access it through a data Model.
Here you can find an example on storing in a file.
Here you can find an example on storing in CoreData.
I personally recommend using coredata for such a large quantity of data. Plist files are more suitable for storing low information quantities (like saving some credentials, some settings, etc).
You need to use DB for this. You can update it from your server when user will have connection, so you don't need to re-submit your app when you will update your vocabulary.
You can use CoreData as #Alex Bartiş told you or you can try another one which becomes popular: Realm
I have some app-related parameters (boolean and string data) which are either set by user through the app, either at its first execution. I don't want this kind of information to be stored by using Core Data, so the options I'm thinking about are:
1) Creating and reading/writing a custom .plist file (let's say, myconfig.plist) to be stored in Documents app folder
2) Saving such info using NSUserDefaults
The kind of information I want to keep is, for example, the last app version that was installed and run in order to check if app is being updated, or a flag telling if some specific set of data has been already loaded without having to check the model.
Which of the options would be the most suitable and safest for this task? Or is even there any better option of handling this?
Thanks
try this if you would check appstore version with your actually app version https://github.com/nicklockwood/iVersion
I am currently thinking on what kind of information, I can store in Info.plist.
I was planning to store the Ip address of the rest server to which the app talks to, but that can be stored as a constant in a configuration file. so what are the other use cases where one uses Info.plist to store some data.
Is it a good practice to store IP address in Info.plist?.
It really depends on your application and what you're trying to achieve, you can store pretty much anything you'd like in a plist if it's one of the value types referenced in Apple's plist documentation which can be found by clicking this part of the sentence.
A plist is just an xml file. You can store whatever you want in it. View a plist file as RAW in Xcode by right clicking on it and you can see.
Yes can store IP Addresses too in it, in the form of string or in some number type.
Here you can see the Property list types and their various representations (From Apple Documentation) below:
i am trying to work on nsuserdefaults but few things are confusing me in apple reference and setting guide they says
Preferences are pieces of information that you store persistently and
use to configure your app. Apps often expose preferences to users so
that they can customize the appearance and behavior of the app. Most
preferences are stored locally using the Cocoa preferences
system—known as the user defaults system. Apps can also store
preferences in a user’s iCloud account using the key-value store.
The user defaults system and key-value store are both designed for
storing simple data types—strings, numbers, dates, Boolean values,
URLs, data objects, and so forth—in a property list. The use of a
property list also means you can organize your preference data using
array and dictionary types. It is also possible to store other objects
in a property list by encoding them into an NSData object first.
but what is users defaults system and further on in this guide they say users defaults database... if they are talking about database then why here they wrote use of plist?
similar question but not helping me
thanks in advance.
NSUserDefaults is a key value store for saving preferences. It works very much like an NSDictionary where you insert an object for a key, and pull it out.
Since the object needs to be saved to disk, only plist serializable objects work, unless you turn them into NSData first.
It is not the type of database you can run SQL queries on.
My application uses the PersistentStore to store data. The keys of the PersistentStore are created at runtime, so there's no way to know all the keys. I'd like to know if there's a way to retrieve or list the persistent store keys used by my application. I want to put them on a ObjectChoiceField and select the one I want to work with.
My application creates a name as a string, and then turns the string into a long value used as a key. I'm currently thinking to store the names of the PersistentStore on a single RMS, and with it retrieve the keys. But I would like to keep this option as a last resort.
The keys of the PS are created at runtime
You really want to use well-known keys rather than generating them at runtime. The persistent store is shared across all apps on the device, and I'm not aware of any way to list all the keys.
You could store all the keys as they are generated, which may be what you are suggesting as your last-resort. You would still need to keep one well-known key, and use that well-known key to store a Vector or array of all the other keys that have been generated.