Quantcast
Channel: Yudiz Solutions Ltd.
Viewing all articles
Browse latest Browse all 595

Which database type Should I follow in my iOS application?

$
0
0

Hummm… In my application I have requirement to deal with database. Which database I should follow? As there are various options available which are as follow:

  1. SQLite
  2. NSUserDefualts
  3. NSCoder
  4. CoreData
  5. Realm

Lets, check each and every option with their pros and cons. So I can decide which option suits for my requirement.

SQLite

Pros

  • You can deal with large number of data.
  • Migration is possible.
  • Simple query just needs to run to fetch data. These queries you have learned in your college time.
  • You can share database file.
  • Cross platform support is possible
  • Browse data is possible
  • Database size is small as compare to Coredata

Cons

  • Slow data fetching process.
  • It’s very complex to add in your project as compare to sqlite.
  • Cannot handle multi threaded situation. If you access two operation on same database table, your database will face deadlock situation.
  • Migration process is very long and complex too. As compare to core data, you have to perform so many steps for migration process.
  • You must have to provide relationships manually.

Comments

Actually, this is a good option but it’s too old. And it is not providing any good feature to handle search and fetch operations like core data and realm is providing. So as per my opinion, if you want to learn how SQLite is working, then you can use this.

NSUserDefaults

Pros

  • Provided by apple.
  • By the way this is not a database, but you can use it as database option to save limited number of data for eg. login token, boolean values, etc.
  • It uses key and value system
  • Very simple to use.
  • You can use this to save small amount of data.

For eg. boolean values.

Cons

  • You cannot use this to store large number data
  • It does not have any type of support to search data by using any query

Comments

Actually this is not a database where you can store large amount of data. So don’t use this if your application scope is big. Because after sometime, you will get stuck as you will find that NSUserDefaults not providing any thing.

NSCoding Protocol

Pros

  • Provided by apple.
  • You can save any view controller with its object without losing any value.
  • You just need to use below two methods to store and fetch data

-(void)encodeWithCoder:(NSCoder*)encoder
-(id)initWithCoder:(NSCoder*)decoder

Cons

  • Its process is slow
  • Again no query method is provided so you have to fetch data manually
  • Store data size is big as compare to NSUserDefault and CoreData

Comments

In last moment, if you have requirement to providing offline support to your application and you don’t have time to go with other option. Then you can use this option. You can store view controller’s data by using NSCoder and then fetch it again to display it. But again for long time support, this option is not preferable.

CoreData

Pros

  • Native framework provided by apple.
  • Very fast processing to fetch data.
  • You can manage large amount of database.
  • Migration process is also simple.
  • Very easy to add in your current source code.
  • Apple provides good feature to handle relationship between two tables. Even SQLite is not have this type of feature.
  • Graph representation is possible.
  • Day by day, apple improving this to make it better. So for long time purpose this is the best option for your application.
  • Multithread is possible but by using different ’NSManagedObjectContext’

Cons

  • Browsing data is much difficult.
  • Database file is not compatible with any other platform like android. So if you are making same application in iOS and android. Then you must have to manage two different database for both platform.
  • Database is not shareable
  • Consuming more memory as compare to SQLite
  • Consuming more space as compared to SQLite

Comments

Definitely you can use this option as your database option. Its fully loaded with necessary features like search, filter etc.

Realm

Pros

  • Very popular in nowadays, this is the first thought in developer’s mind.
  • Easy to Use in your application.
  • By using query you can filter or search any data from database table.
  • Fetching process is faster than core data.
  • Multithread is also possible by using two different objects.
  • Cross platform support is there. So you can use same database for iOS and android version.
  • Share database is possible.
  • You can browse your database too.
  • Migration process is also simple.
  • You can handle large database to.
  • Database size is less as compare to CoreData
  • Less code require to fetch data

Cons

  • It’s not an native framework.
  • More features are not available to handle relationship between two different table. If you are using core data from such a long time, then you can phase this situation only. But for SQLite users will not complain this.
  • Consuming more memory as compare to SQLite
  • Consuming more space as compared to SQLite

Comments

This option is new but good as compare to core data. So you can use this without any issue in your application. Realm also provide good documentation, so you will not phase any kind of problem while implementing it in your application.

Conclusion

From the above pros and cons for all various options, I am suggesting all developers

  1. Only use NSUserDefaults to save only boolean type data. Only consider this for small size of application.
  2. Please don’t use SQLite, instead of you can use Core data or realm. Both options are fully loaded with all type of database functionality.
  3. Now regarding, NSCoder, only use this feature when it is necessary. Don’t make habit to use this. As this option is little bit slow and memory consuming.
  4. Now last, Core Data or realm, see both are good option right now. If you are building application for iOS only then you can use core data. And if your application is for both platform, then you should have to choose realm, because you can use same database file in android or iOS. You don’t have to manage two different database here.

Viewing all articles
Browse latest Browse all 595

Trending Articles