Rebar iOS App Databases

Monkton, Inc. 2019

Rebar allows for apps to have zero to many databases for managing data.

All databases classes must extend the RebarDatabase class to inherit the security configurations for each.

Internally, Rebar manages two databases for file management and internal storage and configuration.

Note: At this time for iOS Core Data is not supported. Rebar ships with FMDB built in. We strongly advise against Core Data as it limits portability between developing apps to run in iOS and Android.

Setup and instantiation

In iOS the app delegate (Which must extend the RebarAppDelegate class) class must register the databases as part of the startup process. Each database should be registered via the database manager's register method. These methods take the class value to map.

class MyAppDelegate: RebarAppDelegate {
	override func configureApp() {
		// Set the configuration

		// Set the Database configuration

Schema customization

For iOS and Android, as below, updates can be easily administered via the verifyUpgrades methods. This allows for the tracking and updates to tables, data, keys, each time the app is run.

For updates to the app, this is where updates to the schema should occur.

Using Databases in iOS

Databases can be retrieved by invoking the RebarDatabaseManager.default.getDatabase(MyAppDatabase.self) method.

This method returns a FMDB mapped database to manage the database connection. The FMDB methods must be leveraged to interact with the database (queues are optimal).

iOS Customization

Schema setup

The schema can be setup, updated, and configured by overriding the verifyUpgrades method. This can

Overriding this method should always call the superclass method verifyUpgrades first.

	static let APP_NAME: String = "MyApp";
	// Check upgrades
	override func verifyUpgrades(db: FMDatabase!) {
		// Always check the parent upgrades
		// Grab the current version for this database
		var currentVersion: Int = self.getCurrentDatabaseVersion(db, app: MyAppDatabase.APP_NAME);
		// Perform the upgrades for versions < accepted
		if (currentVersion < 1) {		
			// Increment the current version 
			currentVersion = 2;
			// Update the current version
			setCurrentDatabaseVersion(db, app: MyAppDatabase.APP_NAME, version: currentVersion);

Bundle file

Implementations must define the source database schema with the bundlePath file. This must be a sqlite database located within the app bundle. The return value should be a string indicating the name of the file, such as myapp.sqlite.

Last Updated: February 02, 2019