From b488de8b5f4e1743f98659ef33ff9b32ce6750c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 9 Jul 2015 05:30:48 +0200 Subject: [PATCH] Carthage WIP --- GRDB Tests/Carthage/iOS/iOS/AppDelegate.swift | 35 ++----------------- .../iOS/iOS/DetailViewController.swift | 11 ------ .../iOS/iOS/MasterViewController.swift | 26 ++++---------- GRDB Tests/Carthage/iOS/iOS/Person.swift | 12 +++---- 4 files changed, 14 insertions(+), 70 deletions(-) diff --git a/GRDB Tests/Carthage/iOS/iOS/AppDelegate.swift b/GRDB Tests/Carthage/iOS/iOS/AppDelegate.swift index 180d15849..4df15c297 100644 --- a/GRDB Tests/Carthage/iOS/iOS/AppDelegate.swift +++ b/GRDB Tests/Carthage/iOS/iOS/AppDelegate.swift @@ -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 { diff --git a/GRDB Tests/Carthage/iOS/iOS/DetailViewController.swift b/GRDB Tests/Carthage/iOS/iOS/DetailViewController.swift index 15b5cf8f1..7a2d06ed2 100644 --- a/GRDB Tests/Carthage/iOS/iOS/DetailViewController.swift +++ b/GRDB Tests/Carthage/iOS/iOS/DetailViewController.swift @@ -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. - } - - } diff --git a/GRDB Tests/Carthage/iOS/iOS/MasterViewController.swift b/GRDB Tests/Carthage/iOS/iOS/MasterViewController.swift index a9c9f0e10..ab2635368 100644 --- a/GRDB Tests/Carthage/iOS/iOS/MasterViewController.swift +++ b/GRDB Tests/Carthage/iOS/iOS/MasterViewController.swift @@ -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) } diff --git a/GRDB Tests/Carthage/iOS/iOS/Person.swift b/GRDB Tests/Carthage/iOS/iOS/Person.swift index 872a147ab..c0796691f 100644 --- a/GRDB Tests/Carthage/iOS/iOS/Person.swift +++ b/GRDB Tests/Carthage/iOS/iOS/Person.swift @@ -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,