mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Carthage WIP
This commit is contained in:
1 parent
7cd52d7ee8
commit
b488de8b5f
4 files changed
+14
-70
No files matched your search
+2
-33
@@ -24,8 +24,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
|
||||
navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem()
|
||||
splitViewController.delegate = self
|
||||
|
||||
// Setup database
|
||||
|
||||
// Database
|
||||
dbQueue = DatabaseQueue()
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPersons") { db in
|
||||
@@ -36,41 +35,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
|
||||
try Person(firstName: "Barbara", lastName: "Streisand").insert(db)
|
||||
try Person(firstName: "Cinderella").insert(db)
|
||||
}
|
||||
do {
|
||||
try migrator.migrate(dbQueue)
|
||||
} catch let error as SQLiteError {
|
||||
fatalError(error.description)
|
||||
} catch let error as RowModelError {
|
||||
fatalError(error.description)
|
||||
} catch {
|
||||
fatalError("\(error)")
|
||||
}
|
||||
try! migrator.migrate(dbQueue)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func applicationWillResignActive(application: UIApplication) {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
func applicationDidEnterBackground(application: UIApplication) {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
}
|
||||
|
||||
func applicationWillEnterForeground(application: UIApplication) {
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(application: UIApplication) {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
func applicationWillTerminate(application: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
// MARK: - Split view
|
||||
|
||||
func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController:UIViewController, ontoPrimaryViewController primaryViewController:UIViewController) -> Bool {
|
||||
|
||||
@@ -12,16 +12,13 @@ class DetailViewController: UIViewController {
|
||||
|
||||
@IBOutlet weak var detailDescriptionLabel: UILabel!
|
||||
|
||||
|
||||
var person: Person? {
|
||||
didSet {
|
||||
// Update the view.
|
||||
self.configureView()
|
||||
}
|
||||
}
|
||||
|
||||
func configureView() {
|
||||
// Update the user interface for the detail item.
|
||||
if let person = self.person {
|
||||
if let label = self.detailDescriptionLabel {
|
||||
label.text = person.fullName
|
||||
@@ -31,15 +28,7 @@ class DetailViewController: UIViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
self.configureView()
|
||||
}
|
||||
|
||||
override func didReceiveMemoryWarning() {
|
||||
super.didReceiveMemoryWarning()
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+6
-20
@@ -33,11 +33,6 @@ class MasterViewController: UITableViewController {
|
||||
super.viewWillAppear(animated)
|
||||
}
|
||||
|
||||
override func didReceiveMemoryWarning() {
|
||||
super.didReceiveMemoryWarning()
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
// MARK: - Segues
|
||||
|
||||
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
||||
@@ -70,23 +65,14 @@ class MasterViewController: UITableViewController {
|
||||
return cell
|
||||
}
|
||||
|
||||
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
|
||||
// Return false if you do not want the specified item to be editable.
|
||||
return true
|
||||
}
|
||||
|
||||
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
|
||||
if editingStyle == .Delete {
|
||||
let person = persons[indexPath.row]
|
||||
try! dbQueue.inTransaction { db in
|
||||
try person.delete(db)
|
||||
return .Commit
|
||||
}
|
||||
persons.removeAtIndex(indexPath.row)
|
||||
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
|
||||
} else if editingStyle == .Insert {
|
||||
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
|
||||
let person = persons[indexPath.row]
|
||||
try! dbQueue.inTransaction { db in
|
||||
try person.delete(db)
|
||||
return .Commit
|
||||
}
|
||||
persons.removeAtIndex(indexPath.row)
|
||||
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
|
||||
}
|
||||
|
||||
|
||||
|
||||
+6
-6
@@ -29,16 +29,16 @@ class Person : RowModel {
|
||||
return Table(named: "persons", primaryKey: .RowID("id"))
|
||||
}
|
||||
|
||||
override func setSQLiteValue(sqliteValue: SQLiteValue, forColumn column: String) {
|
||||
override func setDatabaseValue(dbv: DatabaseValue, forColumn column: String) {
|
||||
switch column {
|
||||
case "id": id = sqliteValue.value()
|
||||
case "firstName": firstName = sqliteValue.value()
|
||||
case "lastName": lastName = sqliteValue.value()
|
||||
default: super.setSQLiteValue(sqliteValue, forColumn: column)
|
||||
case "id": id = dbv.value()
|
||||
case "firstName": firstName = dbv.value()
|
||||
case "lastName": lastName = dbv.value()
|
||||
default: super.setDatabaseValue(dbv, forColumn: column)
|
||||
}
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: SQLiteValueConvertible?] {
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
return [
|
||||
"id": id,
|
||||
"firstName": firstName,
|
||||
|
||||
Reference in new issue
Block a user