diff --git a/CHANGELOG.md b/CHANGELOG.md index 46bdc245c..93868bb86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Release Notes **Breaking Changes** +- `Row(dictionary:)` has been renamed `Row(_:)`. - `RowConvertible.awakeFromFetch()` now takes a database argument. diff --git a/GRDB Tests/Public/Core/Row/DictionaryRowTests.swift b/GRDB Tests/Public/Core/Row/DictionaryRowTests.swift index a9d56af15..b6ddd7776 100644 --- a/GRDB Tests/Public/Core/Row/DictionaryRowTests.swift +++ b/GRDB Tests/Public/Core/Row/DictionaryRowTests.swift @@ -4,7 +4,7 @@ import GRDB class DictionaryRowTests: GRDBTestCase { func testRowAsSequence() { - let row = Row(dictionary: ["a": 0, "b": 1, "c": 2]) + let row = Row(["a": 0, "b": 1, "c": 2]) var columnNames = Set() var ints = Set() @@ -22,7 +22,7 @@ class DictionaryRowTests: GRDBTestCase { func testRowValueAtIndex() { let dictionary: [String: DatabaseValueConvertible?] = ["a": 0, "b": 1, "c": 2] - let row = Row(dictionary: dictionary) + let row = Row(dictionary) let aIndex = dictionary.startIndex.distanceTo(dictionary.indexForKey("a")!) let bIndex = dictionary.startIndex.distanceTo(dictionary.indexForKey("b")!) @@ -65,7 +65,7 @@ class DictionaryRowTests: GRDBTestCase { } func testRowValueNamed() { - let row = Row(dictionary: ["a": 0, "b": 1, "c": 2]) + let row = Row(["a": 0, "b": 1, "c": 2]) // Int extraction, form 1 XCTAssertEqual(row.value(named: "a") as Int, 0) @@ -103,22 +103,22 @@ class DictionaryRowTests: GRDBTestCase { } func testRowCount() { - let row = Row(dictionary: ["a": 0, "b": 1, "c": 2]) + let row = Row(["a": 0, "b": 1, "c": 2]) XCTAssertEqual(row.count, 3) } func testRowColumnNames() { - let row = Row(dictionary: ["a": 0, "b": 1, "c": 2]) + let row = Row(["a": 0, "b": 1, "c": 2]) XCTAssertEqual(Array(row.columnNames).sort(), ["a", "b", "c"]) } func testRowDatabaseValues() { - let row = Row(dictionary: ["a": 0, "b": 1, "c": 2]) + let row = Row(["a": 0, "b": 1, "c": 2]) XCTAssertEqual(row.databaseValues.sort { ($0.value() as Int!) < ($1.value() as Int!) }, [0.databaseValue, 1.databaseValue, 2.databaseValue]) } func testRowSubscriptIsCaseInsensitive() { - let row = Row(dictionary: ["name": "foo"]) + let row = Row(["name": "foo"]) XCTAssertEqual(row["name"], "foo".databaseValue) XCTAssertEqual(row["NAME"], "foo".databaseValue) XCTAssertEqual(row["NaMe"], "foo".databaseValue) @@ -128,7 +128,7 @@ class DictionaryRowTests: GRDBTestCase { } func testRowHasColumnIsCaseInsensitive() { - let row = Row(dictionary: ["nAmE": "foo", "foo": 1]) + let row = Row(["nAmE": "foo", "foo": 1]) XCTAssertTrue(row.hasColumn("name")) XCTAssertTrue(row.hasColumn("NAME")) XCTAssertTrue(row.hasColumn("Name")) diff --git a/GRDB Tests/Public/Core/Row/RowConvertibleTests.swift b/GRDB Tests/Public/Core/Row/RowConvertibleTests.swift index 7f98b0fed..512d11eab 100644 --- a/GRDB Tests/Public/Core/Row/RowConvertibleTests.swift +++ b/GRDB Tests/Public/Core/Row/RowConvertibleTests.swift @@ -31,7 +31,7 @@ class RowConvertibleTests: GRDBTestCase { } func testRowInitializer() { - let row = Row(dictionary: ["firstName": "Arthur", "lastName": "Martin"]) + let row = Row(["firstName": "Arthur", "lastName": "Martin"]) let s = SimpleRowConvertible.fromRow(row) XCTAssertEqual(s.firstName, "Arthur") XCTAssertEqual(s.lastName, "Martin") diff --git a/GRDB Tests/Public/Foundation/Row+FoundationTests.swift b/GRDB Tests/Public/Foundation/Row+FoundationTests.swift index 4245849e1..4a10f7aaf 100644 --- a/GRDB Tests/Public/Foundation/Row+FoundationTests.swift +++ b/GRDB Tests/Public/Foundation/Row+FoundationTests.swift @@ -5,13 +5,13 @@ class RowFoundationTests: GRDBTestCase { func testRowFromInvalidNSDictionary() { let dictionary: NSDictionary = ["a": NSObject()] - let row = Row(dictionary: dictionary) + let row = Row(dictionary) XCTAssertTrue(row == nil) } func testRowFromNSDictionary() { let dictionary: NSDictionary = ["a": "foo", "b": 1, "c": NSNull(), "d": NSDate(timeIntervalSince1970: 1443642439)] - let row = Row(dictionary: dictionary)! + let row = Row(dictionary)! XCTAssertEqual(row.count, 4) XCTAssertEqual(row.value(named: "a") as String, "foo") @@ -21,7 +21,7 @@ class RowFoundationTests: GRDBTestCase { } func testRowToNSDictionary() { - let row = Row(dictionary: ["a": "foo", "b": 1, "c": nil, "d": NSDate(timeIntervalSince1970: 1443642439)]) + let row = Row(["a": "foo", "b": 1, "c": nil, "d": NSDate(timeIntervalSince1970: 1443642439)]) let dictionary = row.toNSDictionary() XCTAssertEqual(dictionary.count, 4) XCTAssertTrue((dictionary["a"] as! NSString).isEqualToString("foo")) diff --git a/GRDB Tests/Public/Record/RecordEditedTests.swift b/GRDB Tests/Public/Record/RecordEditedTests.swift index 8b1b164a2..b86e65c22 100644 --- a/GRDB Tests/Public/Record/RecordEditedTests.swift +++ b/GRDB Tests/Public/Record/RecordEditedTests.swift @@ -44,7 +44,7 @@ class RecordEditedTests: GRDBTestCase { func testRecordIsEditedAfterInitFromRow() { // Create a Record from a row. The row may not come from the database. // So it is edited. - let row = Row(dictionary: ["name": "Arthur", "age": 41]) + let row = Row(["name": "Arthur", "age": 41]) let person = Person(row) XCTAssertTrue(person.hasPersistentChangedValues) } @@ -80,7 +80,7 @@ class RecordEditedTests: GRDBTestCase { // Compare to an Int let record = IntegerPropertyOnRealAffinityColumn.fetchOne(db, "SELECT * FROM t")! - let row2 = Row(dictionary: record.persistentDictionary) + let row2 = Row(record.persistentDictionary) switch row2["value"]!.storage { case .Int64(let int64): XCTAssertEqual(int64, 1) @@ -268,7 +268,7 @@ class RecordEditedTests: GRDBTestCase { } func testChangesAfterInitFromRow() { - let person = Person(Row(dictionary:["name": "Arthur", "age": 41])) + let person = Person(Row(["name": "Arthur", "age": 41])) let changes = person.persistentChangedValues XCTAssertEqual(changes.count, 4) for (column, old) in changes { diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index 0729f668a..d330a8fcb 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -24,7 +24,7 @@ public final class Row: CollectionType { } /// Builds a row from an dictionary of values. - public init(dictionary: [String: DatabaseValueConvertible?]) { + public init(_ dictionary: [String: DatabaseValueConvertible?]) { var databaseDictionary = [String: DatabaseValue]() for (key, value) in dictionary { databaseDictionary[key] = value?.databaseValue ?? .Null diff --git a/GRDB/Foundation/Row+Foundation.swift b/GRDB/Foundation/Row+Foundation.swift index 17ecf0923..6a67aa936 100644 --- a/GRDB/Foundation/Row+Foundation.swift +++ b/GRDB/Foundation/Row+Foundation.swift @@ -10,7 +10,7 @@ extension Row { /// NSString, NSURL). /// /// - parameter dictionary: An NSDictionary. - public convenience init?(dictionary: NSDictionary) { + public convenience init?(_ dictionary: NSDictionary) { var initDictionary = [String: DatabaseValueConvertible?]() for (key, value) in dictionary { guard let columnName = key as? String else { @@ -21,7 +21,7 @@ extension Row { } initDictionary[columnName] = databaseValue } - self.init(dictionary: initDictionary) + self.init(initDictionary) } /// Converts a row to an NSDictionary. diff --git a/GRDB/Record/Record.swift b/GRDB/Record/Record.swift index 448fde5cf..cc8730559 100644 --- a/GRDB/Record/Record.swift +++ b/GRDB/Record/Record.swift @@ -110,7 +110,7 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable /// - returns: A copy of self. @warn_unused_result public func copy() -> Self { - let copy = self.dynamicType.fromRow(Row(dictionary: persistentDictionary)) + let copy = self.dynamicType.fromRow(Row(persistentDictionary)) copy.referenceRow = referenceRow return copy } @@ -141,7 +141,7 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable if newValue { referenceRow = nil } else { - referenceRow = Row(dictionary: persistentDictionary) + referenceRow = Row(persistentDictionary) } } } diff --git a/README.md b/README.md index e5c587bf4..0137fe105 100644 --- a/README.md +++ b/README.md @@ -492,10 +492,10 @@ for (columnName, databaseValue) in row { ... } // ("foo", 1), ("foo", 2) Rows is a fundamental type in GRDB, used by many other APIs. -From time to time, you'll want to build a custom one from scratch. Use the dictionary initializer: +From time to time, you'll want to build a custom one from scratch. Use the dictionary and NSDictionary initializers: ```swift -Row(dictionary: ["name": "foo", "date": nil]) +Row(["name": "foo", "date": nil]) ``` See [Values](#values) for more information on supported types. diff --git a/TODO.md b/TODO.md index eec4da356..73d162e8b 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,3 @@ -- [ ] Row dictionary initializer should be replaced with a initializer from sequences of (string, value) pairs (including dictionaries). - [ ] Unify Database.execute() and Database.executeMultiStatement() Not sure: @@ -27,4 +26,4 @@ Reading list: - https://www.sqlite.org/undoredo.html - http://www.sqlite.org/intern-v-extern-blob.html - List of documentation keywords: https://swift.org/documentation/api-design-guidelines.html#special-instructions -- https://www.zetetic.net/sqlcipher/ \ No newline at end of file +- https://www.zetetic.net/sqlcipher/