mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
Xcode 8 WIP
This commit is contained in:
1 parent
f45b9a3757
commit
0944ed331b
4 files changed
+32
-41
No files matched your search
@@ -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!
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -711,7 +711,7 @@ private final class FetchedRecordsObserver<Record: RowConvertible> : 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<Record: RowConvertible> : Transaction
|
||||
|
||||
var changes = [TableViewChange<Record>]()
|
||||
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<Record: RowConvertible> : 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
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user