iOS development Crash course in how to build an native application for iPhone.
i will be start from beginning till publishing on Apple Store step by step.
this session # 5
4. UserDefaults
All iOS apps have a built in data dictionary
that stores small amounts of user settings
for as long as the app is installed.
This system, called UserDefaults can save
integers, booleans, strings, arrays,
dictionaries, dates and more, but you
should be careful not to save too much data
because it will slow the launch of your app.
5. UserDefaults
When you set values like that, they
become permanent – you can quit the app
then re-launch and they'll still be there,
so it's the ideal way to store app
configuration data.
NSUserDefault is light weight storage section where user can save their
persistent data.
NSUserDefault Storing the data in the form of key and value pair.
6. How to save user settings
using UserDefaults
To save:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:@"TextToSave" forKey:@“keyToFindText"];
[userdefault synchronize];
To load:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *textToLoad = [prefs stringForKey:@"keyToFindText"];
7. How to save user settings using
UserDefaults
When it comes to reading data back, it's still easy but has an important proviso:
UserDefaults will return a default value if the setting can't be found. You need to
know what these default values are so that you don't confuse them with real
values that you set. Here they are:
integer(forKey:) returns an integer if the key existed, or 0 if not.
bool(forKey:) returns a boolean if the key existed, or false if not.
float(forKey:) returns a float if the key existed, or 0.0 if not.
double(forKey:) returns a double if the key existed, or 0.0 if not.
object(forKey:) returns AnyObject? so you need to conditionally typecast it to
your data type.
With that in mind, you can read values back like this:
8. How to save user settings using
UserDefaults
Use the appropriate getter/setter method to retrieve or set values: Getters &
Setters
boolForKey: setBool:forKey:
doubleForKey: setDouble:forKey:
floatForKey: setFloat:forKey:
integerForKey: setInteger:forKey:
objectForKey: setObject:forKey:
arrayForKey: setObject:forKey:
dataForKey: setObject:forKey:
dictionaryForKey: setObject:forKey:
stringArrayForKey: setObject:forKey:
stringForKey: setObject:forKey:
14. UITableView
It is used for displaying a vertically
scrollable view which consists of a
number of cells (generally reusable cells).
It has special features like headers,
footers, rows, and section.