From 0944ed331b0f5a376a4090fbced253487943565f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 14 Jun 2016 14:04:04 +0200 Subject: [PATCH] Xcode 8 WIP --- GRDB/Core/DatabasePool.swift | 8 ++-- GRDB/Core/DatabaseQueue.swift | 8 ++-- GRDB/Record/FetchedRecordsController.swift | 14 +++--- .../FetchedRecordsControlleriOSTests.swift | 43 ++++++++----------- 4 files changed, 32 insertions(+), 41 deletions(-) diff --git a/GRDB/Core/DatabasePool.swift b/GRDB/Core/DatabasePool.swift index 9976427b5..1440799de 100644 --- a/GRDB/Core/DatabasePool.swift +++ b/GRDB/Core/DatabasePool.swift @@ -90,7 +90,7 @@ public final class DatabasePool { // // https://developer.apple.com/library/mac/releasenotes/Foundation/RN-Foundation/index.html#10_11Error // Explicit unregistration is required before iOS 9 and OS X 10.11. - NSNotificationCenter.default().removeObserver(self) + NotificationCenter.default().removeObserver(self) } #endif @@ -157,9 +157,9 @@ public final class DatabasePool { /// enters background. public func setupMemoryManagement(in application: UIApplication) { self.application = application - let center = NSNotificationCenter.default() - center.addObserver(self, selector: #selector(DatabasePool.applicationDidReceiveMemoryWarning(_:)), name: UIApplicationDidReceiveMemoryWarningNotification, object: nil) - center.addObserver(self, selector: #selector(DatabasePool.applicationDidEnterBackground(_:)), name: UIApplicationDidEnterBackgroundNotification, object: nil) + let center = NotificationCenter.default() + center.addObserver(self, selector: #selector(DatabasePool.applicationDidReceiveMemoryWarning(_:)), name: .UIApplicationDidReceiveMemoryWarning, object: nil) + center.addObserver(self, selector: #selector(DatabasePool.applicationDidEnterBackground(_:)), name: .UIApplicationDidEnterBackground, object: nil) } private var application: UIApplication! diff --git a/GRDB/Core/DatabaseQueue.swift b/GRDB/Core/DatabaseQueue.swift index a78bc20c9..54a426d39 100644 --- a/GRDB/Core/DatabaseQueue.swift +++ b/GRDB/Core/DatabaseQueue.swift @@ -48,7 +48,7 @@ public final class DatabaseQueue { // // https://developer.apple.com/library/mac/releasenotes/Foundation/RN-Foundation/index.html#10_11Error // Explicit unregistration is required before iOS 9 and OS X 10.11. - NSNotificationCenter.default().removeObserver(self) + NotificationCenter.default().removeObserver(self) } #endif @@ -137,9 +137,9 @@ public final class DatabaseQueue { /// enters background. public func setupMemoryManagement(in application: UIApplication) { self.application = application - let center = NSNotificationCenter.default() - center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidReceiveMemoryWarning(_:)), name: UIApplicationDidReceiveMemoryWarningNotification, object: nil) - center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidEnterBackground(_:)), name: UIApplicationDidEnterBackgroundNotification, object: nil) + let center = NotificationCenter.default() + center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidReceiveMemoryWarning(_:)), name: .UIApplicationDidReceiveMemoryWarning, object: nil) + center.addObserver(self, selector: #selector(DatabaseQueue.applicationDidEnterBackground(_:)), name: .UIApplicationDidEnterBackground, object: nil) } private var application: UIApplication? diff --git a/GRDB/Record/FetchedRecordsController.swift b/GRDB/Record/FetchedRecordsController.swift index 90a620e52..1b2f699b6 100644 --- a/GRDB/Record/FetchedRecordsController.swift +++ b/GRDB/Record/FetchedRecordsController.swift @@ -711,7 +711,7 @@ private final class FetchedRecordsObserver : Transaction guard let fetchedItems = fetchedItems, let index = fetchedItems.index(where: { isSameItem($0, item) }) else { return nil } - return NSIndexPath(forRow: index, inSection: 0) + return NSIndexPath(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(forRow: row, inSection: 0)) + let deletion = TableViewChange.deletion(item: item, indexPath: NSIndexPath(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(forRow: col, inSection: 0)) + let insertion = TableViewChange.insertion(item: item, indexPath: NSIndexPath(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(forRow: sx, inSection: 0)) + let deletion = TableViewChange.deletion(item: s[sx], indexPath: NSIndexPath(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(forRow: tx, inSection: 0)) + let insertion = TableViewChange.insertion(item: t[tx], indexPath: NSIndexPath(row: tx, section: 0)) ins.append(insertion) d[sx+1][tx+1] = ins } else { - let deletion = TableViewChange.deletion(item: s[sx], indexPath: NSIndexPath(forRow: sx, inSection: 0)) - let insertion = TableViewChange.insertion(item: t[tx], indexPath: NSIndexPath(forRow: tx, inSection: 0)) + 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)) sub.append(deletion) sub.append(insertion) d[sx+1][tx+1] = sub diff --git a/Tests/Public/FetchedRecordsController/FetchedRecordsControlleriOSTests.swift b/Tests/Public/FetchedRecordsController/FetchedRecordsControlleriOSTests.swift index 47cbfd411..d4395d67a 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(forRow:inSection:), but works on OSX as well. -private func makeIndexPath(forRow row:Int, inSection section: Int) -> NSIndexPath { - #if os(iOS) - return NSIndexPath(forRow: row, inSection: section) - #else - return [section, row].withUnsafeBufferPointer { buffer in NSIndexPath(indexes: buffer.baseAddress, length: buffer.count) } - #endif -} - /// Same as NSIndexPath.row, but works on OSX as well. private func row(for indexPath:NSIndexPath) -> Int { #if os(iOS) @@ -130,8 +121,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: makeIndexPath(forRow: 0, inSection: 0)).name, "Arthur") - XCTAssertEqual(controller.indexPath(for: arthur), makeIndexPath(forRow: 0, inSection: 0)) + XCTAssertEqual(controller.record(at: NSIndexPath(row: 0, section: 0)).name, "Arthur") + XCTAssertEqual(controller.indexPath(for: arthur), NSIndexPath(row: 0, section: 0)) } } @@ -169,7 +160,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Arthur") switch recorder.changes[0].event { case .insertion(let indexPath): - XCTAssertEqual(indexPath, makeIndexPath(forRow: 0, inSection: 0)) + XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) default: XCTFail() } @@ -193,7 +184,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Barbara") switch recorder.changes[0].event { case .insertion(let indexPath): - XCTAssertEqual(indexPath, makeIndexPath(forRow: 1, inSection: 0)) + XCTAssertEqual(indexPath, NSIndexPath(row: 1, section: 0)) default: XCTFail() } @@ -247,7 +238,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Craig") switch recorder.changes[0].event { case .update(let indexPath, let changes): - XCTAssertEqual(indexPath, makeIndexPath(forRow: 0, inSection: 0)) + XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) XCTAssertEqual(changes, ["name": "Arthur".databaseValue]) default: XCTFail() @@ -272,7 +263,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Danielle") switch recorder.changes[0].event { case .update(let indexPath, let changes): - XCTAssertEqual(indexPath, makeIndexPath(forRow: 1, inSection: 0)) + XCTAssertEqual(indexPath, NSIndexPath(row: 1, section: 0)) XCTAssertEqual(changes, ["name": "Barbara".databaseValue]) default: XCTFail() @@ -319,7 +310,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Arthur") switch recorder.changes[0].event { case .deletion(let indexPath): - XCTAssertEqual(indexPath, makeIndexPath(forRow: 0, inSection: 0)) + XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) default: XCTFail() } @@ -340,7 +331,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Barbara") switch recorder.changes[0].event { case .deletion(let indexPath): - XCTAssertEqual(indexPath, makeIndexPath(forRow: 0, inSection: 0)) + XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) default: XCTFail() } @@ -387,8 +378,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, makeIndexPath(forRow: 0, inSection: 0)) - XCTAssertEqual(newIndexPath, makeIndexPath(forRow: 1, inSection: 0)) + XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) + XCTAssertEqual(newIndexPath, NSIndexPath(row: 1, section: 0)) XCTAssertEqual(changes, ["name": "Arthur".databaseValue]) default: XCTFail() @@ -443,7 +434,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.bookCount, 0) switch recorder.changes[0].event { case .update(let indexPath, let changes): - XCTAssertEqual(indexPath, makeIndexPath(forRow: 0, inSection: 0)) + XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) XCTAssertEqual(changes, ["bookCount": 1.databaseValue]) default: XCTFail() @@ -619,8 +610,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, makeIndexPath(forRow: 1, inSection: 0)) - XCTAssertEqual(newIndexPath, makeIndexPath(forRow: 0, inSection: 0)) + XCTAssertEqual(indexPath, NSIndexPath(row: 1, section: 0)) + XCTAssertEqual(newIndexPath, NSIndexPath(row: 0, section: 0)) XCTAssertTrue(changes.isEmpty) default: XCTFail() @@ -642,7 +633,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[1].record.name, "Craig") switch recorder.changes[0].event { case .deletion(let indexPath): - XCTAssertEqual(indexPath, makeIndexPath(forRow: 0, inSection: 0)) + XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) default: XCTFail() } @@ -650,8 +641,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, makeIndexPath(forRow: 1, inSection: 0)) - XCTAssertEqual(newIndexPath, makeIndexPath(forRow: 0, inSection: 0)) + XCTAssertEqual(indexPath, NSIndexPath(row: 1, section: 0)) + XCTAssertEqual(newIndexPath, NSIndexPath(row: 0, section: 0)) XCTAssertEqual(changes, ["name": "Arthur".databaseValue]) default: XCTFail() @@ -689,7 +680,7 @@ class FetchedRecordsControlleriOSTests: GRDBTestCase { XCTAssertEqual(recorder.changes[0].record.name, "Arthur") switch recorder.changes[0].event { case .insertion(let indexPath): - XCTAssertEqual(indexPath, makeIndexPath(forRow: 0, inSection: 0)) + XCTAssertEqual(indexPath, NSIndexPath(row: 0, section: 0)) default: XCTFail() }