Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Wain is right but I think as you want to store small amount of data for further use, the most efficient ways is to use <code>NSUserDefault</code>.</p> <p><code>NSUserDefault</code> stores data in <code>NSDictionary</code> type things.</p> <p>I think this is the step you have to take:</p> <p>1- check if data exists. I mean if user selected the number if the last run of your app. So in <code>viewDidLoad</code> method:</p> <pre><code>NSMutableDictionary *userDefaultDataDictionary = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:ALL_DATA_KEY] mutableCopy]; if (userDefaultDataDictionary) { // so the dictionary exists, which means user has entered the number in previous app run // and you can read it from the NSDictionaty: if(userDefaultDataDictionary[LABLE_KEY]){ //and store it } } </code></pre> <p>2 - you can implement some method like <code>syncronize</code> to store data in <code>NSUserDefault</code> every time something has been changed.</p> <pre><code>- (void) synchronize { NSMutableDictionary *dictionaryForUserDefault = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:ALL_DATA_KEY] mutableCopy]; if(!dictionaryForUserDefault) dictionaryForUserDefault = [[NSMutableDictionary alloc] init]; dictionaryForUserDefault[LABLE_KEY] = //data you want to store [[NSUserDefaults standardUserDefaults] setObject:dictionaryForUserDefault forKey:ALL_DATA_KEY]; [[NSUserDefaults standardUserDefaults] synchronize]; } </code></pre> <p>P.S. and don't forget to <code>#define</code> your keys for your dictionary:</p> <pre><code>#define LABLE_KEY @"Lables" #define ALL_DATA_KEY @"AllData" </code></pre>
 

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