Mobile applications are of two types – online and offline. Online applications have to be connected to an external server for functioning. When there is no network connectivity, these application stops functioning. Offline applications, on the other hand, do not need to be connected to external servers. These applications work with data stored locally on the mobile.
For mobile applications with local data storage, accessing data is very easy and does not need network connectivity. Applications of this kind are very quick and make the user more comfortable.
Types of data storage in iOS
iOS has as excellent collection of tools and frameworks for storing, accessing and sharing data. Core data is a data modeling framework for object-oriented Cocoa touch applications, while SQLite is a low-level relational database and NSUserDefaults is a quick and easy way to store small amounts of data.
NSUserDefault is used to store small amounts of data. It allows the application to set and get its preferences and also allows the user to store it in a file. The stored values can be accessed globally within the whole application.
NSUserDefault caches the information. This helps the user avoid opening default databases, each time for default values.
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults setObject:@”Tarams” forKey:@”Company”];
companyName = [standardUserDefaults objectForKey:@”Company”];
SQ-Lite is a light weight relational database which can be added easily into your application. It uses SQL API to manipulate the data in tables.
SQ-Lite implements most of SQL-92 standard, but it lacks few features in it. For example, it cannot write views but it supports complex queries, it has limited ALTER TABLE support and it can’t modify or delete columns.
Core data is a data modelling framework built on the model-view-controller(MVC) pattern. It is expressed in terms of entities and relationships. We can create entities and add relationships in the graphical form. This helps to eliminate most of the basic code and can be easily added into your application.
Core data provides an API to deal with common functionalities such as Save, Delete, Undo etc. which allows us to build applications easily. Using this we need not worry about SQL query and its syntax.
In the next article I will discuss in detail about SQLite and Core data and how they differ.