Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am assuming an array, but it will work with dictionaries too.</p> <p>Userdefaults, Core Data and Plists can all be read/write but if you use a plist you need to pay attention in what dir you put it. See the plist part down below.</p> <p>Core Data I think it's way too much overkill, it's just strings. It's supposed to be used when you want to persist more complex objects.</p> <p><strong>NSUserDefaults</strong>:</p> <p>It's pretty fast and easy to do, though it's supposed to store only user settings. To write them to the userdefaults:</p> <pre><code>NSArray *stringsArray = [[NSArray alloc] arrayWithObjects: string1, string2, string3, nil]; [[NSUserDefaults standardUserDefaults] setObject:stringsArray forKey:@"MyStrings"]; [[NSUserDefaults standardUserDefaults] synchronize]; </code></pre> <p>To read the from the userdefaults:</p> <pre><code>NSArray *stringsArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"MyStrings"]; </code></pre> <p><strong>Plist</strong>:</p> <p>If your strings are going to be modified you will need to write and read a plist but you cant't write into your app's resources.</p> <ol> <li><p>To have a read/write plist first find the documents directory</p> <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *stringsPlistPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Strings.plist"]; </code></pre></li> <li><p>Create the array (I am assuming the strings are string1, ...)</p> <pre><code>NSArray *stringsArray = [[NSArray alloc] arrayWithObjects: string1, string2, string3, nil]; </code></pre></li> <li><p>Write it to file</p> <pre><code>[stringsArray writeToFile:stringsPlistPath atomically:YES]; </code></pre></li> </ol> <p>To read the plist:</p> <ol> <li><p>Find the documents directory</p> <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *stringsPlistPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Strings.plist"]; </code></pre></li> <li><p>Read it in:</p> <pre><code>NSArray *stringsArray = [NSArray arrayWithContentsOfFile:stringsPlistPath]; </code></pre></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload