diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/project.pbxproj b/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/project.pbxproj index b0904b3a2..37a666c71 100644 --- a/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/project.pbxproj +++ b/DemoApps/GRDBDemoiOS/GRDBDemoiOS.xcodeproj/project.pbxproj @@ -22,6 +22,76 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 5657AAFA1D107C20006283EF /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 568C7AC51CA6C6BF00796484 /* GRDB.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 560FC54D1CB003810014AA8E; + remoteInfo = GRDBCipherOSX; + }; + 5657AAFC1D107C20006283EF /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 568C7AC51CA6C6BF00796484 /* GRDB.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 560FC5B01CB00B880014AA8E; + remoteInfo = GRDBCipherOSXTests; + }; + 5657AAFE1D107C20006283EF /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 568C7AC51CA6C6BF00796484 /* GRDB.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 5671566C1CB16729007DC145; + remoteInfo = GRDBCipherOSXEncryptedTests; + }; + 5657AB001D107C20006283EF /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 568C7AC51CA6C6BF00796484 /* GRDB.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = F3BA805A1CFB2BB2003DC1BA; + remoteInfo = GRDBCustomSQLiteOSX; + }; + 5657AB021D107C20006283EF /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 568C7AC51CA6C6BF00796484 /* GRDB.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = F3BA809B1CFB2F6F003DC1BA; + remoteInfo = GRDBCustomSQLiteOSXTests; + }; + 5657AB041D107C20006283EF /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 568C7AC51CA6C6BF00796484 /* GRDB.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 56AFCA231CB1A8BB00F48B96; + remoteInfo = GRDBCipheriOS; + }; + 5657AB061D107C20006283EF /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 568C7AC51CA6C6BF00796484 /* GRDB.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 56AFCA7F1CB1AA9900F48B96; + remoteInfo = GRDBCipheriOSTests; + }; + 5657AB081D107C20006283EF /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 568C7AC51CA6C6BF00796484 /* GRDB.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 56AFCAD71CB1ABC800F48B96; + remoteInfo = GRDBCipheriOSEncryptedTests; + }; + 5657AB0A1D107C20006283EF /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 568C7AC51CA6C6BF00796484 /* GRDB.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = F3BA7FFE1CFB25E4003DC1BA; + remoteInfo = GRDBCustomSQLiteiOS; + }; + 5657AB0C1D107C20006283EF /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 568C7AC51CA6C6BF00796484 /* GRDB.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = F3BA80411CFB2AD7003DC1BA; + remoteInfo = GRDBCustomSQLiteiOSTests; + }; 568C7ACE1CA6C6BF00796484 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 568C7AC51CA6C6BF00796484 /* GRDB.xcodeproj */; @@ -151,11 +221,21 @@ isa = PBXGroup; children = ( 568C7ACF1CA6C6BF00796484 /* GRDB.framework */, - 568C7AD11CA6C6BF00796484 /* GRDBOSXCrashTests.xctest */, 568C7AD31CA6C6BF00796484 /* GRDBTests.xctest */, 568C7AD51CA6C6BF00796484 /* GRDBOSXPerformanceTests.xctest */, + 568C7AD11CA6C6BF00796484 /* GRDBOSXCrashTests.xctest */, + 5657AAFB1D107C20006283EF /* GRDBCipher.framework */, + 5657AAFD1D107C20006283EF /* GRDBTests.xctest */, + 5657AAFF1D107C20006283EF /* GRDBCipherOSXEncryptedTests.xctest */, + 5657AB011D107C20006283EF /* GRDBCustomSQLite.framework */, + 5657AB031D107C20006283EF /* GRDBCustomSQLiteOSXTests.xctest */, 568C7AD71CA6C6BF00796484 /* GRDB.framework */, 568C7AD91CA6C6BF00796484 /* GRDBTests.xctest */, + 5657AB051D107C20006283EF /* GRDBCipher.framework */, + 5657AB071D107C20006283EF /* GRDBTests.xctest */, + 5657AB091D107C20006283EF /* GRDBTests.xctest */, + 5657AB0B1D107C20006283EF /* GRDBCustomSQLite.framework */, + 5657AB0D1D107C20006283EF /* GRDBCustomSQLiteiOSTests.xctest */, ); name = Products; sourceTree = ""; @@ -200,7 +280,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = Pierlis; TargetAttributes = { 568C7A951CA6C63100796484 = { @@ -234,6 +314,76 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ + 5657AAFB1D107C20006283EF /* GRDBCipher.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = GRDBCipher.framework; + remoteRef = 5657AAFA1D107C20006283EF /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 5657AAFD1D107C20006283EF /* GRDBTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = GRDBTests.xctest; + remoteRef = 5657AAFC1D107C20006283EF /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 5657AAFF1D107C20006283EF /* GRDBCipherOSXEncryptedTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = GRDBCipherOSXEncryptedTests.xctest; + remoteRef = 5657AAFE1D107C20006283EF /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 5657AB011D107C20006283EF /* GRDBCustomSQLite.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = GRDBCustomSQLite.framework; + remoteRef = 5657AB001D107C20006283EF /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 5657AB031D107C20006283EF /* GRDBCustomSQLiteOSXTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = GRDBCustomSQLiteOSXTests.xctest; + remoteRef = 5657AB021D107C20006283EF /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 5657AB051D107C20006283EF /* GRDBCipher.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = GRDBCipher.framework; + remoteRef = 5657AB041D107C20006283EF /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 5657AB071D107C20006283EF /* GRDBTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = GRDBTests.xctest; + remoteRef = 5657AB061D107C20006283EF /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 5657AB091D107C20006283EF /* GRDBTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = GRDBTests.xctest; + remoteRef = 5657AB081D107C20006283EF /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 5657AB0B1D107C20006283EF /* GRDBCustomSQLite.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = GRDBCustomSQLite.framework; + remoteRef = 5657AB0A1D107C20006283EF /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 5657AB0D1D107C20006283EF /* GRDBCustomSQLiteiOSTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = GRDBCustomSQLiteiOSTests.xctest; + remoteRef = 5657AB0C1D107C20006283EF /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; 568C7ACF1CA6C6BF00796484 /* GRDB.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; @@ -422,10 +572,10 @@ 568C7AA91CA6C63100796484 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = GRDBDemoiOS/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -438,16 +588,17 @@ 568C7AAA1CA6C63100796484 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = GRDBDemoiOS/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = GRDB.GRDBDemoiOS; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; }; name = Release; }; diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Base.lproj/Main.storyboard b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Base.lproj/Main.storyboard index ac4ded116..12b3c428d 100644 --- a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Base.lproj/Main.storyboard +++ b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/Base.lproj/Main.storyboard @@ -1,9 +1,10 @@ - + - + + @@ -11,29 +12,29 @@ - + - + - + - + @@ -64,21 +65,20 @@ - + - + - + - + - @@ -94,14 +94,13 @@ - + - + - @@ -154,24 +153,24 @@ - + - + - + - + @@ -181,17 +180,17 @@ - + - + @@ -251,29 +250,29 @@ - + - + - + - + @@ -306,6 +305,6 @@ - + diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonEditionViewController.swift b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonEditionViewController.swift index 0da8627fa..775635a13 100644 --- a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonEditionViewController.swift +++ b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonEditionViewController.swift @@ -85,7 +85,7 @@ extension PersonEditionViewController: UITextFieldDelegate { nameTextField.becomeFirstResponder() } - override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: NSIndexPath) { + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: false) let cell = tableView.cellForRow(at: indexPath) if cell === nameCell { diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonsViewController.swift b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonsViewController.swift index 2b3de0073..5039f7966 100644 --- a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonsViewController.swift +++ b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/PersonsViewController.swift @@ -86,15 +86,15 @@ extension PersonsViewController : PersonEditionViewControllerDelegate { performSegue(withIdentifier: "NewPerson", sender: sender) } - @IBAction func cancelPersonEdition(segue: UIStoryboardSegue) { + @IBAction func cancelPersonEdition(_ segue: UIStoryboardSegue) { // Person creation: cancel button was tapped } - @IBAction func commitPersonEdition(segue: UIStoryboardSegue) { + @IBAction func commitPersonEdition(_ segue: UIStoryboardSegue) { // Person creation: commit button was tapped let controller = segue.sourceViewController as! PersonEditionViewController controller.applyChanges() - let person = controller.person + let person = controller.person! if !person.name.isEmpty { try! dbQueue.inDatabase { db in try person.save(db) @@ -105,7 +105,7 @@ extension PersonsViewController : PersonEditionViewControllerDelegate { func personEditionControllerDidComplete(_ controller: PersonEditionViewController) { // Person edition: back button was tapped controller.applyChanges() - let person = controller.person + let person = controller.person! if !person.name.isEmpty { try! dbQueue.inDatabase { db in try person.save(db) @@ -118,7 +118,7 @@ extension PersonsViewController : PersonEditionViewControllerDelegate { // MARK: - UITableViewDataSource extension PersonsViewController { - func configure(_ cell: UITableViewCell, at indexPath: NSIndexPath) { + func configure(_ cell: UITableViewCell, at indexPath: IndexPath) { let person = personsController.record(at: indexPath) cell.textLabel?.text = person.name cell.detailTextLabel?.text = abs(person.score) > 1 ? "\(person.score) points" : "0 point" @@ -132,17 +132,17 @@ extension PersonsViewController { return personsController.sections[section].numberOfRecords } - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell { + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Person", for: indexPath) configure(cell, at: indexPath) return cell } - override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: NSIndexPath) { + override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { // Delete the person let person = personsController.record(at: indexPath) try! dbQueue.inDatabase { db in - try person.delete(db) + _ = try person.delete(db) } } } diff --git a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/SimplePersonsViewController.swift b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/SimplePersonsViewController.swift index 18e3331a6..e09a397b4 100644 --- a/DemoApps/GRDBDemoiOS/GRDBDemoiOS/SimplePersonsViewController.swift +++ b/DemoApps/GRDBDemoiOS/GRDBDemoiOS/SimplePersonsViewController.swift @@ -54,15 +54,15 @@ extension SimplePersonsViewController : PersonEditionViewControllerDelegate { performSegue(withIdentifier: "NewPerson", sender: sender) } - @IBAction func cancelPersonEdition(segue: UIStoryboardSegue) { + @IBAction func cancelPersonEdition(_ segue: UIStoryboardSegue) { // Person creation: cancel button was tapped } - @IBAction func commitPersonEdition(segue: UIStoryboardSegue) { + @IBAction func commitPersonEdition(_ segue: UIStoryboardSegue) { // Person creation: commit button was tapped let controller = segue.sourceViewController as! PersonEditionViewController controller.applyChanges() - let person = controller.person + let person = controller.person! if !person.name.isEmpty { try! dbQueue.inDatabase { db in try person.save(db) @@ -73,7 +73,7 @@ extension SimplePersonsViewController : PersonEditionViewControllerDelegate { func personEditionControllerDidComplete(_ controller: PersonEditionViewController) { // Person edition: back button was tapped controller.applyChanges() - let person = controller.person + let person = controller.person! if !person.name.isEmpty { try! dbQueue.inDatabase { db in try person.save(db) @@ -86,7 +86,7 @@ extension SimplePersonsViewController : PersonEditionViewControllerDelegate { // MARK: - UITableViewDataSource extension SimplePersonsViewController { - func configure(_ cell: UITableViewCell, at indexPath: NSIndexPath) { + func configure(_ cell: UITableViewCell, at indexPath: IndexPath) { let person = persons[indexPath.row] cell.textLabel?.text = person.name cell.detailTextLabel?.text = abs(person.score) > 1 ? "\(person.score) points" : "0 point" @@ -96,17 +96,17 @@ extension SimplePersonsViewController { return persons.count } - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell { + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Person", for: indexPath) configure(cell, at: indexPath) return cell } - override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: NSIndexPath) { + override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { // Delete the person let person = persons[indexPath.row] try! dbQueue.inDatabase { db in - try person.delete(db) + _ = try person.delete(db) } persons.remove(at: indexPath.row) tableView.deleteRows(at: [indexPath], with: .fade) diff --git a/GRDB/Record/FetchedRecordsController.swift b/GRDB/Record/FetchedRecordsController.swift index 1b2f699b6..25ad16800 100644 --- a/GRDB/Record/FetchedRecordsController.swift +++ b/GRDB/Record/FetchedRecordsController.swift @@ -680,11 +680,11 @@ private final class FetchedRecordsObserver : Transaction /// /// If indexPath does not describe a valid index path in the fetched /// records, a fatal error is raised. - public func record(at indexPath: NSIndexPath) -> Record { + public func record(at indexPath: IndexPath) -> Record { guard let fetchedItems = fetchedItems else { fatalError("performFetch() has not been called.") } - return fetchedItems[indexPath.index(atPosition: 1)].record + return fetchedItems[indexPath.row].record } @@ -706,12 +706,12 @@ private final class FetchedRecordsObserver : Transaction /// /// - returns: The index path of *record* in the fetched records, or nil /// if record could not be found. - public func indexPath(for record: Record) -> NSIndexPath? { + public func indexPath(for record: Record) -> IndexPath? { let item = Item(row: Row(record.persistentDictionary)) guard let fetchedItems = fetchedItems, let index = fetchedItems.index(where: { isSameItem($0, item) }) else { return nil } - return NSIndexPath(row: index, section: 0) + return IndexPath(row: index, section: 0) } } @@ -727,14 +727,14 @@ private final class FetchedRecordsObserver : Transaction var changes = [TableViewChange]() for (row, item) in s.enumerated() { - let deletion = TableViewChange.deletion(item: item, indexPath: NSIndexPath(row: row, section: 0)) + let deletion = TableViewChange.deletion(item: item, indexPath: IndexPath(row: row, section: 0)) changes.append(deletion) d[row + 1][0] = changes } changes.removeAll() for (col, item) in t.enumerated() { - let insertion = TableViewChange.insertion(item: item, indexPath: NSIndexPath(row: col, section: 0)) + let insertion = TableViewChange.insertion(item: item, indexPath: IndexPath(row: col, section: 0)) changes.append(insertion) d[0][col + 1] = changes } @@ -757,16 +757,16 @@ private final class FetchedRecordsObserver : Transaction // Record operation. let minimumCount = min(del.count, ins.count, sub.count) if del.count == minimumCount { - let deletion = TableViewChange.deletion(item: s[sx], indexPath: NSIndexPath(row: sx, section: 0)) + let deletion = TableViewChange.deletion(item: s[sx], indexPath: IndexPath(row: sx, section: 0)) del.append(deletion) d[sx+1][tx+1] = del } else if ins.count == minimumCount { - let insertion = TableViewChange.insertion(item: t[tx], indexPath: NSIndexPath(row: tx, section: 0)) + let insertion = TableViewChange.insertion(item: t[tx], indexPath: IndexPath(row: tx, section: 0)) ins.append(insertion) d[sx+1][tx+1] = ins } else { - let deletion = TableViewChange.deletion(item: s[sx], indexPath: NSIndexPath(row: sx, section: 0)) - let insertion = TableViewChange.insertion(item: t[tx], indexPath: NSIndexPath(row: tx, section: 0)) + let deletion = TableViewChange.deletion(item: s[sx], indexPath: IndexPath(row: sx, section: 0)) + let insertion = TableViewChange.insertion(item: t[tx], indexPath: IndexPath(row: tx, section: 0)) sub.append(deletion) sub.append(insertion) d[sx+1][tx+1] = sub @@ -855,10 +855,10 @@ private final class FetchedRecordsObserver : Transaction } private enum TableViewChange { - case insertion(item: Item, indexPath: NSIndexPath) - case deletion(item: Item, indexPath: NSIndexPath) - case move(item: Item, indexPath: NSIndexPath, newIndexPath: NSIndexPath, changes: [String: DatabaseValue]) - case update(item: Item, indexPath: NSIndexPath, changes: [String: DatabaseValue]) + case insertion(item: Item, indexPath: IndexPath) + case deletion(item: Item, indexPath: IndexPath) + case move(item: Item, indexPath: IndexPath, newIndexPath: IndexPath, changes: [String: DatabaseValue]) + case update(item: Item, indexPath: IndexPath, changes: [String: DatabaseValue]) } extension TableViewChange { @@ -914,20 +914,20 @@ private final class FetchedRecordsObserver : Transaction public enum TableViewEvent { /// An insertion event, at given indexPath. - case insertion(indexPath: NSIndexPath) + case insertion(indexPath: IndexPath) /// A deletion event, at given indexPath. - case deletion(indexPath: NSIndexPath) + case deletion(indexPath: IndexPath) /// A move event, from indexPath to newIndexPath. The *changes* are a /// dictionary whose keys are column names, and values the old values that /// have been changed. - case move(indexPath: NSIndexPath, newIndexPath: NSIndexPath, changes: [String: DatabaseValue]) + case move(indexPath: IndexPath, newIndexPath: IndexPath, changes: [String: DatabaseValue]) /// An update event, at given indexPath. The *changes* are a dictionary /// whose keys are column names, and values the old values that have /// been changed. - case update(indexPath: NSIndexPath, changes: [String: DatabaseValue]) + case update(indexPath: IndexPath, changes: [String: DatabaseValue]) } extension TableViewEvent: CustomStringConvertible { diff --git a/Tests/Public/FetchedRecordsController/FetchedRecordsControlleriOSTests.swift b/Tests/Public/FetchedRecordsController/FetchedRecordsControlleriOSTests.swift index d4395d67a..a3a2ebc97 100644 --- a/Tests/Public/FetchedRecordsController/FetchedRecordsControlleriOSTests.swift +++ b/Tests/Public/FetchedRecordsController/FetchedRecordsControlleriOSTests.swift @@ -7,15 +7,6 @@ import XCTest import GRDB #endif -/// Same as NSIndexPath.row, but works on OSX as well. -private func row(for indexPath:NSIndexPath) -> Int { - #if os(iOS) - return indexPath.row - #else - return indexPath.indexAtPosition(1) - #endif -} - private class ChangesRecorder { var changes: [(record: Record, event: TableViewEvent)] = [] var recordsBeforeChanges: [Record]! @@ -121,8 +112,8 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(controller.sections[0].records[0].name, "Arthur") XCTAssertEqual(controller.fetchedRecords!.count, 1) XCTAssertEqual(controller.fetchedRecords![0].name, "Arthur") - XCTAssertEqual(controller.record(at: NSIndexPath(row: 0, section: 0)).name, "Arthur") - XCTAssertEqual(controller.indexPath(for: arthur), NSIndexPath(row: 0, section: 0)) + XCTAssertEqual(controller.record(at: IndexPath(row: 0, section: 0)).name, "Arthur") + XCTAssertEqual(controller.indexPath(for: arthur), IndexPath(row: 0, section: 0)) } } @@ -160,7 +151,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Arthur") switch recorder.changes[0].event { case .insertion(let indexPath): - XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) + XCTAssertEqual(indexPath, IndexPath(row: 0, section: 0)) default: XCTFail() } @@ -184,7 +175,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Barbara") switch recorder.changes[0].event { case .insertion(let indexPath): - XCTAssertEqual(indexPath, NSIndexPath(row: 1, section: 0)) + XCTAssertEqual(indexPath, IndexPath(row: 1, section: 0)) default: XCTFail() } @@ -238,7 +229,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Craig") switch recorder.changes[0].event { case .update(let indexPath, let changes): - XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) + XCTAssertEqual(indexPath, IndexPath(row: 0, section: 0)) XCTAssertEqual(changes, ["name": "Arthur".databaseValue]) default: XCTFail() @@ -263,7 +254,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Danielle") switch recorder.changes[0].event { case .update(let indexPath, let changes): - XCTAssertEqual(indexPath, NSIndexPath(row: 1, section: 0)) + XCTAssertEqual(indexPath, IndexPath(row: 1, section: 0)) XCTAssertEqual(changes, ["name": "Barbara".databaseValue]) default: XCTFail() @@ -310,7 +301,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Arthur") switch recorder.changes[0].event { case .deletion(let indexPath): - XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) + XCTAssertEqual(indexPath, IndexPath(row: 0, section: 0)) default: XCTFail() } @@ -331,7 +322,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Barbara") switch recorder.changes[0].event { case .deletion(let indexPath): - XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) + XCTAssertEqual(indexPath, IndexPath(row: 0, section: 0)) default: XCTFail() } @@ -378,8 +369,8 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Craig") switch recorder.changes[0].event { case .move(let indexPath, let newIndexPath, let changes): - XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) - XCTAssertEqual(newIndexPath, NSIndexPath(row: 1, section: 0)) + XCTAssertEqual(indexPath, IndexPath(row: 0, section: 0)) + XCTAssertEqual(newIndexPath, IndexPath(row: 1, section: 0)) XCTAssertEqual(changes, ["name": "Arthur".databaseValue]) default: XCTFail() @@ -434,7 +425,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.bookCount, 0) switch recorder.changes[0].event { case .update(let indexPath, let changes): - XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) + XCTAssertEqual(indexPath, IndexPath(row: 0, section: 0)) XCTAssertEqual(changes, ["bookCount": 1.databaseValue]) default: XCTFail() @@ -464,28 +455,28 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { case .I(let s, let i): switch event { case .insertion(let indexPath): - return s == name && i == row(for: indexPath) + return s == name && i == indexPath.row default: return false } case .M(let s, let i, let j, let c): switch event { case .move(let indexPath, let newIndexPath, let changes): - return s == name && i == row(for: indexPath) && j == row(for: newIndexPath) && c == changes["name"]!.value() + return s == name && i == indexPath.row && j == newIndexPath.row && c == changes["name"]!.value() default: return false } case .D(let s, let i): switch event { case .deletion(let indexPath): - return s == name && i == row(for: indexPath) + return s == name && i == indexPath.row default: return false } case .U(let s, let i, let c): switch event { case .update(let indexPath, let changes): - return s == name && i == row(for: indexPath) && c == changes["name"]!.value() + return s == name && i == indexPath.row && c == changes["name"]!.value() default: return false } @@ -610,8 +601,8 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Barbara") switch recorder.changes[0].event { case .move(let indexPath, let newIndexPath, let changes): - XCTAssertEqual(indexPath, NSIndexPath(row: 1, section: 0)) - XCTAssertEqual(newIndexPath, NSIndexPath(row: 0, section: 0)) + XCTAssertEqual(indexPath, IndexPath(row: 1, section: 0)) + XCTAssertEqual(newIndexPath, IndexPath(row: 0, section: 0)) XCTAssertTrue(changes.isEmpty) default: XCTFail() @@ -633,7 +624,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[1].record.name, "Craig") switch recorder.changes[0].event { case .deletion(let indexPath): - XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) + XCTAssertEqual(indexPath, IndexPath(row: 0, section: 0)) default: XCTFail() } @@ -641,8 +632,8 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { case .move(let indexPath, let newIndexPath, let changes): // TODO: is it really what we should expect? Wouldn't an update fit better? // What does UITableView think? - XCTAssertEqual(indexPath, NSIndexPath(row: 1, section: 0)) - XCTAssertEqual(newIndexPath, NSIndexPath(row: 0, section: 0)) + XCTAssertEqual(indexPath, IndexPath(row: 1, section: 0)) + XCTAssertEqual(newIndexPath, IndexPath(row: 0, section: 0)) XCTAssertEqual(changes, ["name": "Arthur".databaseValue]) default: XCTFail() @@ -680,7 +671,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Arthur") switch recorder.changes[0].event { case .insertion(let indexPath): - XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) + XCTAssertEqual(indexPath, IndexPath(row: 0, section: 0)) default: XCTFail() }