-
Notifications
You must be signed in to change notification settings - Fork 2
Creating a Table
Jeff Hurray edited this page May 3, 2016
·
1 revision
All structs / classes conforming to SQLiteModel have static methods called createTable and createTableInBackground. Both these methods will create a table for your model in an SQLite database if it doesn't already exist.
// Sync
try Movie.createTable()
// Async
Movie.createTableInBackground { (error: SQLiteModelError?) in
}I recommend calling these methods as early as possible in the application launch process.
####Putting it all together
For an iOS application, you would want to call createTable in the ApplicationDelegate.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
do {
try Movie.createTable()
} catch error {
print(error)
return false
}
// any additional setup here
return true
}###Dropping a Table
You can drop a table with the static dropTable method, but this is not recommended :)
SQLiteModel