From b7dee8b469391b9d257579fa0d2095438ceb12f3 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Fri, 9 Sep 2016 10:48:11 -0700 Subject: [PATCH 01/54] comment out the metadata portions from the Persistable protocol --- .../Shared/YapDatabaseExtensions.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift b/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift index d1cf280..20b84cf 100644 --- a/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift +++ b/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift @@ -181,15 +181,15 @@ defined in this framework. It assumes that all instances of a type are stored in the same YapDatabase collection. */ public protocol Persistable: Identifiable { - - /// The nested type of the metadata. Defaults to Void. - associatedtype MetadataType +// +// /// The nested type of the metadata. Defaults to Void. +// associatedtype MetadataType /// The YapDatabase collection name the type is stored in. static var collection: String { get } - - /// A metadata which is set when reading, and get when writing. - var metadata: MetadataType? { get set } +// +// /// A metadata which is set when reading, and get when writing. +// var metadata: MetadataType? { get set } } extension Persistable { From 11f7543c866702e95bdbdaa1dc66e80951ca594b Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Fri, 9 Sep 2016 17:03:27 -0700 Subject: [PATCH 02/54] fix nometadata versions --- .../Curried_ObjectWithNoMetadata.swift | 3 +- .../Curried/Curried_ValueWithNoMetadata.swift | 3 +- .../Functional_ObjectWithNoMetadata.swift | 130 +++++------- .../Functional_ValueWithNoMetadata.swift | 194 ++++++++---------- .../Persistable_ObjectWithNoMetadata.swift | 9 +- .../Persistable_ValueWithNoMetadata.swift | 3 - 6 files changed, 151 insertions(+), 191 deletions(-) diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithNoMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithNoMetadata.swift index 55d7062..4ec7b60 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithNoMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithNoMetadata.swift @@ -12,8 +12,7 @@ import ValueCoding // MARK: - Persistable extension Persistable where - Self: NSCoding, - Self.MetadataType == Void { + Self: NSCoding { /** Returns a closure which, given a read transaction will return diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithNoMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithNoMetadata.swift index 3fc1df7..60cd00a 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithNoMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithNoMetadata.swift @@ -14,8 +14,7 @@ import ValueCoding extension Persistable where Self: ValueCoding, Self.Coder: NSCoding, - Self.Coder.ValueType == Self, - Self.MetadataType == Void { + Self.Coder.ValueType == Self { /** Returns a closure which, given a read transaction will return diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithNoMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithNoMetadata.swift index 5100354..6cebd10 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithNoMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithNoMetadata.swift @@ -21,11 +21,10 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readAtIndex< - ObjectWithNoMetadata where - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(index: YapDB.Index) -> ObjectWithNoMetadata? { - return readAtIndex(index) as? ObjectWithNoMetadata + Object where + Object: Persistable, + Object: NSCoding>(index: YapDB.Index) -> Object? { + return readAtIndex(index) as? Object } /** @@ -35,12 +34,11 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, ObjectWithNoMetadata where + Indexes, Object where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(indexes: Indexes) -> [ObjectWithNoMetadata] { + Object: Persistable, + Object: NSCoding>(indexes: Indexes) -> [Object] { return indexes.flatMap(readAtIndex) } @@ -51,11 +49,10 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readByKey< - ObjectWithNoMetadata where - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(key: String) -> ObjectWithNoMetadata? { - return readAtIndex(ObjectWithNoMetadata.indexWithKey(key)) + Object where + Object: Persistable, + Object: NSCoding>(key: String) -> Object? { + return readAtIndex(Object.indexWithKey(key)) } /** @@ -65,13 +62,12 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, ObjectWithNoMetadata where + Keys, Object where Keys: SequenceType, Keys.Generator.Element == String, - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(keys: Keys) -> [ObjectWithNoMetadata] { - return readAtIndexes(ObjectWithNoMetadata.indexesWithKeys(keys)) + Object: Persistable, + Object: NSCoding>(keys: Keys) -> [Object] { + return readAtIndexes(Object.indexesWithKeys(keys)) } /** @@ -80,11 +76,10 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAll< - ObjectWithNoMetadata where - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>() -> [ObjectWithNoMetadata] { - return readByKeys(keysInCollection(ObjectWithNoMetadata.collection)) + Object where + Object: Persistable, + Object: NSCoding>() -> [Object] { + return readByKeys(keysInCollection(Object.collection)) } } @@ -97,10 +92,9 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readAtIndex< - ObjectWithNoMetadata where - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(index: YapDB.Index) -> ObjectWithNoMetadata? { + Object where + Object: Persistable, + Object: NSCoding>(index: YapDB.Index) -> Object? { return read { $0.readAtIndex(index) } } @@ -111,12 +105,11 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, ObjectWithNoMetadata where + Indexes, Object where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(indexes: Indexes) -> [ObjectWithNoMetadata] { + Object: Persistable, + Object: NSCoding>(indexes: Indexes) -> [Object] { return read { $0.readAtIndexes(indexes) } } @@ -127,11 +120,10 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readByKey< - ObjectWithNoMetadata where - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(key: String) -> ObjectWithNoMetadata? { - return readAtIndex(ObjectWithNoMetadata.indexWithKey(key)) + Object where + Object: Persistable, + Object: NSCoding>(key: String) -> Object? { + return readAtIndex(Object.indexWithKey(key)) } /** @@ -141,13 +133,12 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, ObjectWithNoMetadata where + Keys, Object where Keys: SequenceType, Keys.Generator.Element == String, - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(keys: Keys) -> [ObjectWithNoMetadata] { - return readAtIndexes(ObjectWithNoMetadata.indexesWithKeys(keys)) + Object: Persistable, + Object: NSCoding>(keys: Keys) -> [Object] { + return readAtIndexes(Object.indexesWithKeys(keys)) } /** @@ -156,10 +147,9 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAll< - ObjectWithNoMetadata where - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>() -> [ObjectWithNoMetadata] { + Object where + Object: Persistable, + Object: NSCoding>() -> [Object] { return read { $0.readAll() } } } @@ -175,10 +165,9 @@ extension WriteTransactionType { - returns: the same item */ public func write< - ObjectWithNoMetadata where - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(item: ObjectWithNoMetadata) -> ObjectWithNoMetadata { + Object where + Object: Persistable, + Object: NSCoding>(item: Object) -> Object { writeAtIndex(item.index, object: item, metadata: .None) return item } @@ -190,12 +179,11 @@ extension WriteTransactionType { - returns: the same items, in an array. */ public func write< - Items, ObjectWithNoMetadata where + Items, Object where Items: SequenceType, - Items.Generator.Element == ObjectWithNoMetadata, - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(items: Items) -> [ObjectWithNoMetadata] { + Items.Generator.Element == Object, + Object: Persistable, + Object: NSCoding>(items: Items) -> [Object] { return items.map(write) } } @@ -209,10 +197,9 @@ extension ConnectionType { - returns: the same item */ public func write< - ObjectWithNoMetadata where - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(item: ObjectWithNoMetadata) -> ObjectWithNoMetadata { + Object where + Object: Persistable, + Object: NSCoding>(item: Object) -> Object { return write { $0.write(item) } } @@ -223,12 +210,11 @@ extension ConnectionType { - returns: the same items, in an array. */ public func write< - Items, ObjectWithNoMetadata where + Items, Object where Items: SequenceType, - Items.Generator.Element == ObjectWithNoMetadata, - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(items: Items) -> [ObjectWithNoMetadata] { + Items.Generator.Element == Object, + Object: Persistable, + Object: NSCoding>(items: Items) -> [Object] { return write { $0.write(items) } } @@ -240,10 +226,9 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - ObjectWithNoMetadata where - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(item: ObjectWithNoMetadata, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (ObjectWithNoMetadata -> Void)? = .None) { + Object where + Object: Persistable, + Object: NSCoding>(item: Object, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (Object -> Void)? = .None) { asyncWrite({ $0.write(item) }, queue: queue, completion: completion) } @@ -255,12 +240,11 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - Items, ObjectWithNoMetadata where + Items, Object where Items: SequenceType, - Items.Generator.Element == ObjectWithNoMetadata, - ObjectWithNoMetadata: Persistable, - ObjectWithNoMetadata: NSCoding, - ObjectWithNoMetadata.MetadataType == Void>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([ObjectWithNoMetadata] -> Void)? = .None) { + Items.Generator.Element == Object, + Object: Persistable, + Object: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([Object] -> Void)? = .None) { asyncWrite({ $0.write(items) }, queue: queue, completion: completion) } } diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWithNoMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWithNoMetadata.swift index f1ebbe5..a29a136 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWithNoMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWithNoMetadata.swift @@ -21,13 +21,12 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readAtIndex< - ValueWithNoMetadata where - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(index: YapDB.Index) -> ValueWithNoMetadata? { - return ValueWithNoMetadata.decode(readAtIndex(index)) + Value where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(index: YapDB.Index) -> Value? { + return Value.decode(readAtIndex(index)) } /** @@ -37,14 +36,13 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, ValueWithNoMetadata where + Indexes, Value where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(indexes: Indexes) -> [ValueWithNoMetadata] { + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(indexes: Indexes) -> [Value] { return indexes.flatMap(readAtIndex) } @@ -55,13 +53,12 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readByKey< - ValueWithNoMetadata where - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(key: String) -> ValueWithNoMetadata? { - return readAtIndex(ValueWithNoMetadata.indexWithKey(key)) + Value where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(key: String) -> Value? { + return readAtIndex(Value.indexWithKey(key)) } /** @@ -71,15 +68,14 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, ValueWithNoMetadata where + Keys, Value where Keys: SequenceType, Keys.Generator.Element == String, - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(keys: Keys) -> [ValueWithNoMetadata] { - return readAtIndexes(ValueWithNoMetadata.indexesWithKeys(keys)) + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(keys: Keys) -> [Value] { + return readAtIndexes(Value.indexesWithKeys(keys)) } /** @@ -88,13 +84,12 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAll< - ValueWithNoMetadata where - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>() -> [ValueWithNoMetadata] { - return readByKeys(keysInCollection(ValueWithNoMetadata.collection)) + Value where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>() -> [Value] { + return readByKeys(keysInCollection(Value.collection)) } } @@ -107,12 +102,11 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readAtIndex< - ValueWithNoMetadata where - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(index: YapDB.Index) -> ValueWithNoMetadata? { + Value where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(index: YapDB.Index) -> Value? { return read { $0.readAtIndex(index) } } @@ -123,14 +117,13 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, ValueWithNoMetadata where + Indexes, Value where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(indexes: Indexes) -> [ValueWithNoMetadata] { + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(indexes: Indexes) -> [Value] { return read { $0.readAtIndexes(indexes) } } @@ -141,13 +134,12 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readByKey< - ValueWithNoMetadata where - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(key: String) -> ValueWithNoMetadata? { - return readAtIndex(ValueWithNoMetadata.indexWithKey(key)) + Value where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(key: String) -> Value? { + return readAtIndex(Value.indexWithKey(key)) } /** @@ -157,15 +149,14 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, ValueWithNoMetadata where + Keys, Value where Keys: SequenceType, Keys.Generator.Element == String, - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(keys: Keys) -> [ValueWithNoMetadata] { - return readAtIndexes(ValueWithNoMetadata.indexesWithKeys(keys)) + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(keys: Keys) -> [Value] { + return readAtIndexes(Value.indexesWithKeys(keys)) } /** @@ -174,12 +165,11 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAll< - ValueWithNoMetadata where - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>() -> [ValueWithNoMetadata] { + Value where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>() -> [Value] { return read { $0.readAll() } } } @@ -194,12 +184,11 @@ extension WriteTransactionType { - parameter item: the item to store. */ public func write< - ValueWithNoMetadata where - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(item: ValueWithNoMetadata) -> ValueWithNoMetadata { + Value where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(item: Value) -> Value { writeAtIndex(item.index, object: item.encoded, metadata: .None) return item } @@ -210,14 +199,13 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ public func write< - Items, ValueWithNoMetadata where + Items, Value where Items: SequenceType, - Items.Generator.Element == ValueWithNoMetadata, - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(items: Items) -> [ValueWithNoMetadata] { + Items.Generator.Element == Value, + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(items: Items) -> [Value] { return items.map(write) } } @@ -230,12 +218,11 @@ extension ConnectionType { - parameter item: the item to store. */ public func write< - ValueWithNoMetadata where - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(item: ValueWithNoMetadata) -> ValueWithNoMetadata { + Value where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(item: Value) -> Value { return write { $0.write(item) } } @@ -245,14 +232,13 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ public func write< - Items, ValueWithNoMetadata where + Items, Value where Items: SequenceType, - Items.Generator.Element == ValueWithNoMetadata, - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(items: Items) -> [ValueWithNoMetadata] { + Items.Generator.Element == Value, + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(items: Items) -> [Value] { return write { $0.write(items) } } @@ -264,12 +250,11 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - ValueWithNoMetadata where - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(item: ValueWithNoMetadata, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (ValueWithNoMetadata -> Void)? = .None) { + Value where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(item: Value, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (Value -> Void)? = .None) { asyncWrite({ $0.write(item) }, queue: queue, completion: completion) } @@ -281,14 +266,13 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - Items, ValueWithNoMetadata where + Items, Value where Items: SequenceType, - Items.Generator.Element == ValueWithNoMetadata, - ValueWithNoMetadata: Persistable, - ValueWithNoMetadata: ValueCoding, - ValueWithNoMetadata.Coder: NSCoding, - ValueWithNoMetadata.Coder.ValueType == ValueWithNoMetadata, - ValueWithNoMetadata.MetadataType == Void>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([ValueWithNoMetadata] -> Void)? = .None) { + Items.Generator.Element == Value, + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([Value] -> Void)? = .None) { asyncWrite({ $0.write(items) }, queue: queue, completion: completion) } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithNoMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithNoMetadata.swift index 17c3b13..e390fd0 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithNoMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithNoMetadata.swift @@ -12,8 +12,7 @@ import ValueCoding // MARK: - Persistable extension Persistable where - Self: NSCoding, - Self.MetadataType == Void { + Self: NSCoding { // Writing @@ -60,8 +59,7 @@ extension Persistable where extension SequenceType where Generator.Element: Persistable, - Generator.Element: NSCoding, - Generator.Element.MetadataType == Void { + Generator.Element: NSCoding { /** Write the items using an existing transaction. @@ -108,8 +106,7 @@ extension SequenceType where extension Readable where ItemType: NSCoding, - ItemType: Persistable, - ItemType.MetadataType == Void { + ItemType: Persistable { func inTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> ItemType? { return transaction.readAtIndex(index) diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithNoMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithNoMetadata.swift index e52e301..3e19487 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithNoMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithNoMetadata.swift @@ -13,7 +13,6 @@ import ValueCoding extension Persistable where Self: ValueCoding, - Self.MetadataType == Void, Self.Coder: NSCoding, Self.Coder.ValueType == Self { @@ -63,7 +62,6 @@ extension Persistable where extension SequenceType where Generator.Element: Persistable, Generator.Element: ValueCoding, - Generator.Element.MetadataType == Void, Generator.Element.Coder: NSCoding, Generator.Element.Coder.ValueType == Generator.Element { @@ -113,7 +111,6 @@ extension SequenceType where extension Readable where ItemType: ValueCoding, ItemType: Persistable, - ItemType.MetadataType == Void, ItemType.Coder: NSCoding, ItemType.Coder.ValueType == ItemType { From e69cc43e0a8cd6a11dc645ffad7201cdb4889acd Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Fri, 9 Sep 2016 17:04:31 -0700 Subject: [PATCH 03/54] fix functional with metadata versions --- .../Functional_ObjectWithObjectMetadata.swift | 155 +++++----- .../Functional_ObjectWithValueMetadata.swift | 219 +++++++------- .../Functional_ValueWIthObjectMetadata.swift | 219 +++++++------- .../Functional_ValueWIthValueMetadata.swift | 283 +++++++++--------- 4 files changed, 436 insertions(+), 440 deletions(-) diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithObjectMetadata.swift index baeb3c9..7eff7f9 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithObjectMetadata.swift @@ -21,15 +21,13 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readAtIndex< - ObjectWithObjectMetadata where - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(index: YapDB.Index) -> ObjectWithObjectMetadata? { - if var item = readAtIndex(index) as? ObjectWithObjectMetadata { - item.metadata = readMetadataAtIndex(index) - return item - } - return .None + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(index: YapDB.Index) -> (Object, Metadata?)? { + guard let item: Object = readAtIndex(index) else { return nil } + let metadata: Metadata? = readMetadataAtIndex(index) + return (item, metadata) } /** @@ -39,12 +37,13 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, ObjectWithObjectMetadata where + Indexes, Object, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(indexes: Indexes) -> [ObjectWithObjectMetadata] { + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(indexes: Indexes) -> [(Object, Metadata?)] { + // FIXME: using flatMap means the output length need not match the input length return indexes.flatMap(readAtIndex) } @@ -55,11 +54,11 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readByKey< - ObjectWithObjectMetadata where - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(key: String) -> ObjectWithObjectMetadata? { - return readAtIndex(ObjectWithObjectMetadata.indexWithKey(key)) + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(key: String) -> (Object, Metadata?)? { + return readAtIndex(Object.indexWithKey(key)) } /** @@ -69,13 +68,13 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, ObjectWithObjectMetadata where + Keys, Object, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(keys: Keys) -> [ObjectWithObjectMetadata] { - return readAtIndexes(ObjectWithObjectMetadata.indexesWithKeys(keys)) + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(keys: Keys) -> [(Object, Metadata?)] { + return readAtIndexes(Object.indexesWithKeys(keys)) } /** @@ -84,11 +83,11 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAll< - ObjectWithObjectMetadata where - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>() -> [ObjectWithObjectMetadata] { - return readByKeys(keysInCollection(ObjectWithObjectMetadata.collection)) + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>() -> [(Object, Metadata?)] { + return readByKeys(keysInCollection(Object.collection)) } } @@ -101,10 +100,10 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readAtIndex< - ObjectWithObjectMetadata where - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(index: YapDB.Index) -> ObjectWithObjectMetadata? { + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(index: YapDB.Index) -> (Object, Metadata?)? { return read { $0.readAtIndex(index) } } @@ -115,12 +114,12 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, ObjectWithObjectMetadata where + Indexes, Object, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(indexes: Indexes) -> [ObjectWithObjectMetadata] { + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(indexes: Indexes) -> [(Object, Metadata?)] { return read { $0.readAtIndexes(indexes) } } @@ -131,11 +130,11 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readByKey< - ObjectWithObjectMetadata where - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(key: String) -> ObjectWithObjectMetadata? { - return readAtIndex(ObjectWithObjectMetadata.indexWithKey(key)) + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(key: String) -> (Object, Metadata?)? { + return readAtIndex(Object.indexWithKey(key)) } /** @@ -145,13 +144,13 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, ObjectWithObjectMetadata where + Keys, Object, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(keys: Keys) -> [ObjectWithObjectMetadata] { - return readAtIndexes(ObjectWithObjectMetadata.indexesWithKeys(keys)) + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(keys: Keys) -> [(Object, Metadata?)] { + return readAtIndexes(Object.indexesWithKeys(keys)) } /** @@ -160,10 +159,10 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAll< - ObjectWithObjectMetadata where - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>() -> [ObjectWithObjectMetadata] { + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>() -> [(Object, Metadata?)] { return read { $0.readAll() } } } @@ -178,11 +177,11 @@ extension WriteTransactionType { - parameter item: the item to store. */ public func write< - ObjectWithObjectMetadata where - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(item: ObjectWithObjectMetadata) -> ObjectWithObjectMetadata { - writeAtIndex(item.index, object: item, metadata: item.metadata) + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(item: (Object, Metadata?)) -> (Object, Metadata?) { + writeAtIndex(item.0.index, object: item.0, metadata: item.1) return item } @@ -192,12 +191,12 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ public func write< - Items, ObjectWithObjectMetadata where + Items, Object, Metadata where Items: SequenceType, - Items.Generator.Element == ObjectWithObjectMetadata, - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(items: Items) -> [ObjectWithObjectMetadata] { + Items.Generator.Element == (Object, Metadata?), + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(items: Items) -> [(Object, Metadata?)] { return items.map(write) } } @@ -210,10 +209,10 @@ extension ConnectionType { - parameter item: the item to store. */ public func write< - ObjectWithObjectMetadata where - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(item: ObjectWithObjectMetadata) -> ObjectWithObjectMetadata { + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(item: (Object, Metadata?)) -> (Object, Metadata?) { return write { $0.write(item) } } @@ -223,12 +222,12 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ public func write< - Items, ObjectWithObjectMetadata where + Items, Object, Metadata where Items: SequenceType, - Items.Generator.Element == ObjectWithObjectMetadata, - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(items: Items) -> [ObjectWithObjectMetadata] { + Items.Generator.Element == (Object, Metadata?), + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(items: Items) -> [(Object, Metadata?)] { return write { $0.write(items) } } @@ -240,10 +239,10 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - ObjectWithObjectMetadata where - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(item: ObjectWithObjectMetadata, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (ObjectWithObjectMetadata -> Void)? = .None) { + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(item: (Object, Metadata?), queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Object, Metadata?) -> Void)? = .None) { asyncWrite({ $0.write(item) }, queue: queue, completion: completion) } @@ -255,12 +254,12 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - Items, ObjectWithObjectMetadata where + Items, Object, Metadata where Items: SequenceType, - Items.Generator.Element == ObjectWithObjectMetadata, - ObjectWithObjectMetadata: Persistable, - ObjectWithObjectMetadata: NSCoding, - ObjectWithObjectMetadata.MetadataType: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([ObjectWithObjectMetadata] -> Void)? = .None) { + Items.Generator.Element == (Object, Metadata?), + Object: Persistable, + Object: NSCoding, + Metadata: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Object, Metadata?)] -> Void)? = .None) { asyncWrite({ $0.write(items) }, queue: queue, completion: completion) } } diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithValueMetadata.swift index 30ee717..cc5f0a8 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithValueMetadata.swift @@ -21,17 +21,15 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readAtIndex< - ObjectWithValueMetadata where - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(index: YapDB.Index) -> ObjectWithValueMetadata? { - if var item = readAtIndex(index) as? ObjectWithValueMetadata { - item.metadata = readMetadataAtIndex(index) - return item - } - return .None + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (Object, Metadata?)? { + guard let item: Object = readAtIndex(index) else { return nil } + let metadata: Metadata? = readMetadataAtIndex(index) + return (item, metadata) } /** @@ -41,14 +39,15 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, ObjectWithValueMetadata where + Indexes, Object, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(indexes: Indexes) -> [ObjectWithValueMetadata] { + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(Object, Metadata?)] { + // FIXME: using flatMap means the output length need not match the input length return indexes.flatMap(readAtIndex) } @@ -59,13 +58,13 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readByKey< - ObjectWithValueMetadata where - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(key: String) -> ObjectWithValueMetadata? { - return readAtIndex(ObjectWithValueMetadata.indexWithKey(key)) + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(key: String) -> (Object, Metadata?)? { + return readAtIndex(Object.indexWithKey(key)) } /** @@ -75,15 +74,15 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, ObjectWithValueMetadata where + Keys, Object, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(keys: Keys) -> [ObjectWithValueMetadata] { - return readAtIndexes(ObjectWithValueMetadata.indexesWithKeys(keys)) + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(Object, Metadata?)] { + return readAtIndexes(Object.indexesWithKeys(keys)) } /** @@ -92,13 +91,13 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAll< - ObjectWithValueMetadata where - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>() -> [ObjectWithValueMetadata] { - return readByKeys(keysInCollection(ObjectWithValueMetadata.collection)) + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>() -> [(Object, Metadata?)] { + return readByKeys(keysInCollection(Object.collection)) } } @@ -111,12 +110,12 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readAtIndex< - ObjectWithValueMetadata where - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(index: YapDB.Index) -> ObjectWithValueMetadata? { + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (Object, Metadata?)? { return read { $0.readAtIndex(index) } } @@ -127,14 +126,14 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, ObjectWithValueMetadata where + Indexes, Object, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(indexes: Indexes) -> [ObjectWithValueMetadata] { + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(Object, Metadata?)] { return read { $0.readAtIndexes(indexes) } } @@ -145,13 +144,13 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readByKey< - ObjectWithValueMetadata where - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(key: String) -> ObjectWithValueMetadata? { - return readAtIndex(ObjectWithValueMetadata.indexWithKey(key)) + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(key: String) -> (Object, Metadata?)? { + return readAtIndex(Object.indexWithKey(key)) } /** @@ -161,15 +160,15 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, ObjectWithValueMetadata where + Keys, Object, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(keys: Keys) -> [ObjectWithValueMetadata] { - return readAtIndexes(ObjectWithValueMetadata.indexesWithKeys(keys)) + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(Object, Metadata?)] { + return readAtIndexes(Object.indexesWithKeys(keys)) } /** @@ -178,12 +177,12 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAll< - ObjectWithValueMetadata where - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>() -> [ObjectWithValueMetadata] { + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>() -> [(Object, Metadata?)] { return read { $0.readAll() } } } @@ -198,13 +197,13 @@ extension WriteTransactionType { - parameter item: the item to store. */ public func write< - ObjectWithValueMetadata where - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(item: ObjectWithValueMetadata) -> ObjectWithValueMetadata { - writeAtIndex(item.index, object: item, metadata: item.metadata?.encoded) + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(item: (Object, Metadata?)) -> (Object, Metadata?) { + writeAtIndex(item.0.index, object: item.0, metadata: item.1?.encoded) return item } @@ -214,14 +213,14 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ public func write< - Items, ObjectWithValueMetadata where + Items, Object, Metadata where Items: SequenceType, - Items.Generator.Element == ObjectWithValueMetadata, - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(items: Items) -> [ObjectWithValueMetadata] { + Items.Generator.Element == (Object, Metadata?), + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(items: Items) -> [(Object, Metadata?)] { return items.map(write) } } @@ -234,12 +233,12 @@ extension ConnectionType { - parameter item: the item to store. */ public func write< - ObjectWithValueMetadata where - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(item: ObjectWithValueMetadata) -> ObjectWithValueMetadata { + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(item: (Object, Metadata?)) -> (Object, Metadata?) { return write { $0.write(item) } } @@ -249,14 +248,14 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ public func write< - Items, ObjectWithValueMetadata where + Items, Object, Metadata where Items: SequenceType, - Items.Generator.Element == ObjectWithValueMetadata, - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(items: Items) -> [ObjectWithValueMetadata] { + Items.Generator.Element == (Object, Metadata?), + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(items: Items) -> [(Object, Metadata?)] { return write { $0.write(items) } } @@ -268,12 +267,12 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - ObjectWithValueMetadata where - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(item: ObjectWithValueMetadata, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (ObjectWithValueMetadata -> Void)? = .None) { + Object, Metadata where + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(item: (Object, Metadata?), queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Object, Metadata?) -> Void)? = .None) { asyncWrite({ $0.write(item) }, queue: queue, completion: completion) } @@ -285,14 +284,14 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - Items, ObjectWithValueMetadata where + Items, Object, Metadata where Items: SequenceType, - Items.Generator.Element == ObjectWithValueMetadata, - ObjectWithValueMetadata: Persistable, - ObjectWithValueMetadata: NSCoding, - ObjectWithValueMetadata.MetadataType: ValueCoding, - ObjectWithValueMetadata.MetadataType.Coder: NSCoding, - ObjectWithValueMetadata.MetadataType.Coder.ValueType == ObjectWithValueMetadata.MetadataType>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([ObjectWithValueMetadata] -> Void)? = .None) { + Items.Generator.Element == (Object, Metadata?), + Object: Persistable, + Object: NSCoding, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Object, Metadata?)] -> Void)? = .None) { asyncWrite({ $0.write(items) }, queue: queue, completion: completion) } } diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthObjectMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthObjectMetadata.swift index 4a09f50..1344b75 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthObjectMetadata.swift @@ -21,17 +21,15 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readAtIndex< - ValueWithObjectMetadata where - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(index: YapDB.Index) -> ValueWithObjectMetadata? { - if var item = ValueWithObjectMetadata.decode(readAtIndex(index)) { - item.metadata = readMetadataAtIndex(index) - return item - } - return .None + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(index: YapDB.Index) -> (Value, Metadata?)? { + guard let item: Value = Value.decode(readAtIndex(index)) else { return nil } + let metadata: Metadata? = readMetadataAtIndex(index) + return (item, metadata) } /** @@ -41,14 +39,15 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, ValueWithObjectMetadata where + Indexes, Value, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(indexes: Indexes) -> [ValueWithObjectMetadata] { + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(indexes: Indexes) -> [(Value, Metadata?)] { + // FIXME: using flatMap means the output length need not match the input length return indexes.flatMap(readAtIndex) } @@ -59,13 +58,13 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readByKey< - ValueWithObjectMetadata where - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(key: String) -> ValueWithObjectMetadata? { - return readAtIndex(ValueWithObjectMetadata.indexWithKey(key)) + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(key: String) -> (Value, Metadata?)? { + return readAtIndex(Value.indexWithKey(key)) } /** @@ -75,15 +74,15 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, ValueWithObjectMetadata where + Keys, Value, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(keys: Keys) -> [ValueWithObjectMetadata] { - return readAtIndexes(ValueWithObjectMetadata.indexesWithKeys(keys)) + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(keys: Keys) -> [(Value, Metadata?)] { + return readAtIndexes(Value.indexesWithKeys(keys)) } /** @@ -92,13 +91,13 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAll< - ValueWithObjectMetadata where - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>() -> [ValueWithObjectMetadata] { - return readByKeys(keysInCollection(ValueWithObjectMetadata.collection)) + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>() -> [(Value, Metadata?)] { + return readByKeys(keysInCollection(Value.collection)) } } @@ -111,12 +110,12 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readAtIndex< - ValueWithObjectMetadata where - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(index: YapDB.Index) -> ValueWithObjectMetadata? { + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(index: YapDB.Index) -> (Value, Metadata?)? { return read { $0.readAtIndex(index) } } @@ -127,14 +126,14 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, ValueWithObjectMetadata where + Indexes, Value, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(indexes: Indexes) -> [ValueWithObjectMetadata] { + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(indexes: Indexes) -> [(Value, Metadata?)] { return read { $0.readAtIndexes(indexes) } } @@ -145,13 +144,13 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readByKey< - ValueWithObjectMetadata where - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(key: String) -> ValueWithObjectMetadata? { - return readAtIndex(ValueWithObjectMetadata.indexWithKey(key)) + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(key: String) -> (Value, Metadata?)? { + return readAtIndex(Value.indexWithKey(key)) } /** @@ -161,15 +160,15 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, ValueWithObjectMetadata where + Keys, Value, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(keys: Keys) -> [ValueWithObjectMetadata] { - return readAtIndexes(ValueWithObjectMetadata.indexesWithKeys(keys)) + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(keys: Keys) -> [(Value, Metadata?)] { + return readAtIndexes(Value.indexesWithKeys(keys)) } /** @@ -178,12 +177,12 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAll< - ValueWithObjectMetadata where - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>() -> [ValueWithObjectMetadata] { + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>() -> [(Value, Metadata?)] { return read { $0.readAll() } } } @@ -198,13 +197,13 @@ extension WriteTransactionType { - parameter item: the item to store. */ public func write< - ValueWithObjectMetadata where - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(item: ValueWithObjectMetadata) -> ValueWithObjectMetadata { - writeAtIndex(item.index, object: item.encoded, metadata: item.metadata) + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(item: (Value, Metadata?)) -> (Value, Metadata?) { + writeAtIndex(item.0.index, object: item.0.encoded, metadata: item.1) return item } @@ -214,14 +213,14 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ public func write< - Items, ValueWithObjectMetadata where + Items, Value, Metadata where Items: SequenceType, - Items.Generator.Element == ValueWithObjectMetadata, - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(items: Items) -> [ValueWithObjectMetadata] { + Items.Generator.Element == (Value, Metadata?), + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(items: Items) -> [(Value, Metadata?)] { return items.map(write) } } @@ -234,12 +233,12 @@ extension ConnectionType { - parameter item: the item to store. */ public func write< - ValueWithObjectMetadata where - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(item: ValueWithObjectMetadata) -> ValueWithObjectMetadata { + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(item: (Value, Metadata?)) -> (Value, Metadata?) { return write { $0.write(item) } } @@ -249,14 +248,14 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ public func write< - Items, ValueWithObjectMetadata where + Items, Value, Metadata where Items: SequenceType, - Items.Generator.Element == ValueWithObjectMetadata, - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(items: Items) -> [ValueWithObjectMetadata] { + Items.Generator.Element == (Value, Metadata?), + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(items: Items) -> [(Value, Metadata?)] { return write { $0.write(items) } } @@ -268,12 +267,12 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - ValueWithObjectMetadata where - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(item: ValueWithObjectMetadata, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (ValueWithObjectMetadata -> Void)? = .None) { + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(item: (Value, Metadata?), queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Value, Metadata?) -> Void)? = .None) { asyncWrite({ $0.write(item) }, queue: queue, completion: completion) } @@ -285,14 +284,14 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - Items, ValueWithObjectMetadata where + Items, Value, Metadata where Items: SequenceType, - Items.Generator.Element == ValueWithObjectMetadata, - ValueWithObjectMetadata: Persistable, - ValueWithObjectMetadata: ValueCoding, - ValueWithObjectMetadata.Coder: NSCoding, - ValueWithObjectMetadata.Coder.ValueType == ValueWithObjectMetadata, - ValueWithObjectMetadata.MetadataType: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([ValueWithObjectMetadata] -> Void)? = .None) { + Items.Generator.Element == (Value, Metadata?), + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Value, Metadata?)] -> Void)? = .None) { asyncWrite({ $0.write(items) }, queue: queue, completion: completion) } } diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthValueMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthValueMetadata.swift index 66bf836..217205d 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthValueMetadata.swift @@ -21,19 +21,17 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readAtIndex< - ValueWithValueMetadata where - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(index: YapDB.Index) -> ValueWithValueMetadata? { - if var item = ValueWithValueMetadata.decode(readAtIndex(index)) { - item.metadata = readMetadataAtIndex(index) - return item - } - return .None + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (Value, Metadata?)? { + guard let item: Value = Value.decode(readAtIndex(index)) else { return nil } + let metadata: Metadata? = readMetadataAtIndex(index) + return (item, metadata) } /** @@ -43,16 +41,17 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, ValueWithValueMetadata where + Indexes, Value, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(indexes: Indexes) -> [ValueWithValueMetadata] { + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(Value, Metadata?)] { + // FIXME: using flatMap means the output length need not match the input length return indexes.flatMap(readAtIndex) } @@ -63,15 +62,15 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readByKey< - ValueWithValueMetadata where - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(key: String) -> ValueWithValueMetadata? { - return readAtIndex(ValueWithValueMetadata.indexWithKey(key)) + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(key: String) -> (Value, Metadata?)? { + return readAtIndex(Value.indexWithKey(key)) } /** @@ -81,17 +80,17 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, ValueWithValueMetadata where + Keys, Value, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(keys: Keys) -> [ValueWithValueMetadata] { - return readAtIndexes(ValueWithValueMetadata.indexesWithKeys(keys)) + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(Value, Metadata?)] { + return readAtIndexes(Value.indexesWithKeys(keys)) } /** @@ -100,15 +99,15 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAll< - ValueWithValueMetadata where - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>() -> [ValueWithValueMetadata] { - return readByKeys(keysInCollection(ValueWithValueMetadata.collection)) + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>() -> [(Value, Metadata?)] { + return readByKeys(keysInCollection(Value.collection)) } } @@ -121,14 +120,14 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readAtIndex< - ValueWithValueMetadata where - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(index: YapDB.Index) -> ValueWithValueMetadata? { + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (Value, Metadata?)? { return read { $0.readAtIndex(index) } } @@ -139,16 +138,16 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, ValueWithValueMetadata where + Indexes, Value, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(indexes: Indexes) -> [ValueWithValueMetadata] { + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(Value, Metadata?)] { return read { $0.readAtIndexes(indexes) } } @@ -159,15 +158,15 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readByKey< - ValueWithValueMetadata where - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(key: String) -> ValueWithValueMetadata? { - return readAtIndex(ValueWithValueMetadata.indexWithKey(key)) + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(key: String) -> (Value, Metadata?)? { + return readAtIndex(Value.indexWithKey(key)) } /** @@ -177,17 +176,17 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, ValueWithValueMetadata where + Keys, Value, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(keys: Keys) -> [ValueWithValueMetadata] { - return readAtIndexes(ValueWithValueMetadata.indexesWithKeys(keys)) + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(Value, Metadata?)] { + return readAtIndexes(Value.indexesWithKeys(keys)) } /** @@ -196,14 +195,14 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAll< - ValueWithValueMetadata where - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>() -> [ValueWithValueMetadata] { + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>() -> [(Value, Metadata?)] { return read { $0.readAll() } } } @@ -218,15 +217,15 @@ extension WriteTransactionType { - parameter item: the item to store. */ public func write< - ValueWithValueMetadata where - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(item: ValueWithValueMetadata) -> ValueWithValueMetadata { - writeAtIndex(item.index, object: item.encoded, metadata: item.metadata?.encoded) + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(item: (Value, Metadata?)) -> (Value, Metadata?) { + writeAtIndex(item.0.index, object: item.0.encoded, metadata: item.1?.encoded) return item } @@ -236,16 +235,16 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ public func write< - Items, ValueWithValueMetadata where + Items, Value, Metadata where Items: SequenceType, - Items.Generator.Element == ValueWithValueMetadata, - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(items: Items) -> [ValueWithValueMetadata] { + Items.Generator.Element == (Value, Metadata?), + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(items: Items) -> [(Value, Metadata?)] { return items.map(write) } } @@ -258,14 +257,14 @@ extension ConnectionType { - parameter item: the item to store. */ public func write< - ValueWithValueMetadata where - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(item: ValueWithValueMetadata) -> ValueWithValueMetadata { + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(item: (Value, Metadata?)) -> (Value, Metadata?) { return write { $0.write(item) } } @@ -275,16 +274,16 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ public func write< - Items, ValueWithValueMetadata where + Items, Value, Metadata where Items: SequenceType, - Items.Generator.Element == ValueWithValueMetadata, - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(items: Items) -> [ValueWithValueMetadata] { + Items.Generator.Element == (Value, Metadata?), + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(items: Items) -> [(Value, Metadata?)] { return write { $0.write(items) } } @@ -296,14 +295,14 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - ValueWithValueMetadata where - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(item: ValueWithValueMetadata, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (ValueWithValueMetadata -> Void)? = .None) { + Value, Metadata where + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(item: (Value, Metadata?), queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Value, Metadata?) -> Void)? = .None) { asyncWrite({ $0.write(item) }, queue: queue, completion: completion) } @@ -315,16 +314,16 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - Items, ValueWithValueMetadata where + Items, Value, Metadata where Items: SequenceType, - Items.Generator.Element == ValueWithValueMetadata, - ValueWithValueMetadata: Persistable, - ValueWithValueMetadata: ValueCoding, - ValueWithValueMetadata.Coder: NSCoding, - ValueWithValueMetadata.Coder.ValueType == ValueWithValueMetadata, - ValueWithValueMetadata.MetadataType: ValueCoding, - ValueWithValueMetadata.MetadataType.Coder: NSCoding, - ValueWithValueMetadata.MetadataType.Coder.ValueType == ValueWithValueMetadata.MetadataType>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([ValueWithValueMetadata] -> Void)? = .None) { + Items.Generator.Element == (Value, Metadata?), + Value: Persistable, + Value: ValueCoding, + Value.Coder: NSCoding, + Value.Coder.ValueType == Value, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Value, Metadata?)] -> Void)? = .None) { asyncWrite({ $0.write(items) }, queue: queue, completion: completion) } } From 39b9461cdca840643fa40409d3d1cb9953344e7d Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Fri, 9 Sep 2016 17:04:42 -0700 Subject: [PATCH 04/54] fix persistable versions --- .../Persistable_AnyWithObjectMetadata.swift | 26 +-- .../Persistable_AnyWithValueMetadata.swift | 46 +++-- ...Persistable_ObjectWithObjectMetadata.swift | 119 ++++++----- .../Persistable_ObjectWithValueMetadata.swift | 190 +++++++++++++----- .../Persistable_ValueWithObjectMetadata.swift | 118 ++++++----- .../Persistable_ValueWithValueMetadata.swift | 190 +++++++++++++----- 6 files changed, 466 insertions(+), 223 deletions(-) diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithObjectMetadata.swift index 13cf725..6208e01 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithObjectMetadata.swift @@ -12,27 +12,26 @@ import ValueCoding // MARK: - Readable extension Readable where - ItemType: Persistable, - ItemType.MetadataType: NSCoding { + ItemType: Persistable { - func metadataInTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> ItemType.MetadataType? { + func metadataInTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> Metadata? { return transaction.readMetadataAtIndex(index) } - func metadataAtIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> ItemType.MetadataType? { + func metadataAtIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> Metadata? { return { self.metadataInTransaction($0, atIndex: index) } } - func metadataInTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> ItemType.MetadataType? { + func metadataInTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> Metadata? { return { self.metadataInTransaction(transaction, atIndex: $0) } } func metadataAtIndexesInTransaction< - Indexes where + Indexes, Metadata where Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [ItemType.MetadataType] { - let atIndex = metadataInTransactionAtIndex - return { indexes.flatMap(atIndex($0)) } + Indexes.Generator.Element == YapDB.Index, + Metadata: NSCoding>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [Metadata] { + return { indexes.flatMap(self.metadataInTransactionAtIndex($0)) } } /** @@ -41,7 +40,9 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType.MetadataType` */ - public func metadataAtIndex(index: YapDB.Index) -> ItemType.MetadataType? { + public func metadataAtIndex< + Metadata where + Metadata: NSCoding>(index: YapDB.Index) -> Metadata? { return sync(metadataAtIndexInTransaction(index)) } @@ -52,9 +53,10 @@ extension Readable where - returns: an array of `ItemType.MetadataType` */ public func metadataAtIndexes< - Indexes where + Indexes, Metadata where Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> [ItemType.MetadataType] { + Indexes.Generator.Element == YapDB.Index, + Metadata: NSCoding>(indexes: Indexes) -> [Metadata] { return sync(metadataAtIndexesInTransaction(indexes)) } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithValueMetadata.swift index c27762b..1011383 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithValueMetadata.swift @@ -12,29 +12,40 @@ import ValueCoding // MARK: - Readable extension Readable where - ItemType: Persistable, - ItemType.MetadataType: ValueCoding, - ItemType.MetadataType.Coder: NSCoding, - ItemType.MetadataType.Coder.ValueType == ItemType.MetadataType { + ItemType: Persistable { - func metadataInTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> ItemType.MetadataType? { + func metadataInTransaction< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> Metadata? { return transaction.readMetadataAtIndex(index) } - func metadataAtIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> ItemType.MetadataType? { + func metadataAtIndexInTransaction< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Database.Connection.ReadTransaction -> Metadata? { return { self.metadataInTransaction($0, atIndex: index) } } - func metadataInTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> ItemType.MetadataType? { + func metadataInTransactionAtIndex< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> Metadata? { return { self.metadataInTransaction(transaction, atIndex: $0) } } func metadataAtIndexesInTransaction< - Indexes where + Indexes, Metadata where Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [ItemType.MetadataType] { - let atIndex = metadataInTransactionAtIndex - return { indexes.flatMap(atIndex($0)) } + Indexes.Generator.Element == YapDB.Index, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [Metadata] { + return { indexes.flatMap(self.metadataInTransactionAtIndex($0)) } } /** @@ -43,7 +54,11 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType.MetadataType` */ - public func metadataAtIndex(index: YapDB.Index) -> ItemType.MetadataType? { + public func metadataAtIndex< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Metadata? { return sync(metadataAtIndexInTransaction(index)) } @@ -54,9 +69,12 @@ extension Readable where - returns: an array of `ItemType.MetadataType` */ public func metadataAtIndexes< - Indexes where + Indexes, Metadata where Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> [ItemType.MetadataType] { + Indexes.Generator.Element == YapDB.Index, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [Metadata] { return sync(metadataAtIndexesInTransaction(indexes)) } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift index e910b72..49f9770 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift @@ -7,13 +7,11 @@ // import Foundation -import ValueCoding // MARK: - Persistable extension Persistable where - Self: NSCoding, - Self.MetadataType: NSCoding { + Self: NSCoding { // Writing @@ -23,8 +21,11 @@ extension Persistable where - parameter transaction: a YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(transaction: WriteTransaction) -> Self { - return transaction.write(self) + public func write< + WriteTransaction, Metadata where + WriteTransaction: WriteTransactionType, + Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { + return transaction.write((self, metadata)) } /** @@ -33,8 +34,11 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: the receiver. */ - public func write(connection: Connection) -> Self { - return connection.write(self) + public func write< + Connection, Metadata where + Connection: ConnectionType, + Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { + return connection.write((self, metadata)) } /** @@ -43,8 +47,11 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (Self -> Void)? = .None) { - return connection.asyncWrite(self, queue: queue, completion: completion) + public func asyncWrite< + Connection, Metadata where + Connection: ConnectionType, + Metadata: NSCoding>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { + return connection.asyncWrite((self, metadata), queue: queue, completion: completion) } /** @@ -53,15 +60,17 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.write(self) } + public func writeOperation< + Connection, Metadata where + Connection: ConnectionType, + Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> NSOperation { + return NSBlockOperation { connection.write((self, metadata)) } } } extension SequenceType where Generator.Element: Persistable, - Generator.Element: NSCoding, - Generator.Element.MetadataType: NSCoding { + Generator.Element: NSCoding { /** Write the items using an existing transaction. @@ -69,8 +78,12 @@ extension SequenceType where - parameter transaction: a WriteTransactionType e.g. YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(transaction: WriteTransaction) -> [Generator.Element] { - return transaction.write(self) + public func write< + WriteTransaction, Metadata where + WriteTransaction: WriteTransactionType, + Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return transaction.write(items) } /** @@ -79,8 +92,12 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: the receiver. */ - public func write(connection: Connection) -> [Generator.Element] { - return connection.write(self) + public func write< + Connection, Metadata where + Connection: ConnectionType, + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return connection.write(items) } /** @@ -89,8 +106,12 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([Generator.Element] -> Void)? = .None) { - return connection.asyncWrite(self, queue: queue, completion: completion) + public func asyncWrite< + Connection, Metadata where + Connection: ConnectionType, + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return connection.asyncWrite(items, queue: queue, completion: completion) } /** @@ -99,8 +120,12 @@ extension SequenceType where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.write(self) } + public func writeOperation< + Connection, Metadata where + Connection: ConnectionType, + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> NSOperation { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return NSBlockOperation { connection.write(items) } } } @@ -109,46 +134,44 @@ extension SequenceType where extension Readable where ItemType: NSCoding, - ItemType: Persistable, - ItemType.MetadataType: NSCoding { + ItemType: Persistable { - func inTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> ItemType? { + func inTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { return transaction.readAtIndex(index) } - func inTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> ItemType? { + func inTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { return { self.inTransaction(transaction, atIndex: $0) } } - func atIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> ItemType? { + func atIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { return { self.inTransaction($0, atIndex: index) } } func atIndexesInTransaction< - Indexes where + Indexes, Metadata where Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [ItemType] { - let atIndex = inTransactionAtIndex - return { indexes.flatMap(atIndex($0)) } + Indexes.Generator.Element == YapDB.Index, + Metadata: NSCoding>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + return { indexes.flatMap(self.inTransactionAtIndex($0)) } } - func inTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> ItemType? { + func inTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { return inTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func inTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> ItemType? { + func inTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { return { self.inTransaction(transaction, byKey: $0) } } - func byKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> ItemType? { + func byKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { return { self.inTransaction($0, byKey: key) } } - func byKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [ItemType] { - let byKey = inTransactionByKey + func byKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(byKey(transaction)) + return keys.flatMap(self.inTransactionByKey(transaction)) } } @@ -158,7 +181,7 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func atIndex(index: YapDB.Index) -> ItemType? { + public func atIndex(index: YapDB.Index) -> (ItemType, Metadata?)? { return sync(atIndexInTransaction(index)) } @@ -169,9 +192,10 @@ extension Readable where - returns: an array of `ItemType` */ public func atIndexes< - Indexes where + Indexes, Metadata where Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> [ItemType] { + Indexes.Generator.Element == YapDB.Index, + Metadata: NSCoding>(indexes: Indexes) -> [(ItemType, Metadata?)] { return sync(atIndexesInTransaction(indexes)) } @@ -181,7 +205,7 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func byKey(key: String) -> ItemType? { + public func byKey(key: String) -> (ItemType, Metadata?)? { return sync(byKeyInTransaction(key)) } @@ -192,9 +216,10 @@ extension Readable where - returns: an array of `ItemType` */ public func byKeys< - Keys where + Keys, Metadata where Keys: SequenceType, - Keys.Generator.Element == String>(keys: Keys) -> [ItemType] { + Keys.Generator.Element == String, + Metadata: NSCoding>(keys: Keys) -> [(ItemType, Metadata?)] { return sync(byKeysInTransaction(Array(keys))) } @@ -203,7 +228,7 @@ extension Readable where - returns: an array of `ItemType` */ - public func all() -> [ItemType] { + public func all() -> [(ItemType, Metadata?)] { return sync(byKeysInTransaction()) } @@ -213,11 +238,11 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func filterExisting(keys: [String]) -> (existing: [ItemType], missing: [String]) { - let existingInTransaction = byKeysInTransaction(keys) - return sync { transaction -> ([ItemType], [String]) in + public func filterExisting(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { + let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = byKeysInTransaction(keys) + return sync { transaction -> ([(ItemType, Metadata?)], [String]) in let existing = existingInTransaction(transaction) - let existingKeys = existing.map(keyForPersistable) + let existingKeys = existing.map {keyForPersistable($0.0)} let missingKeys = keys.filter { !existingKeys.contains($0) } return (existing, missingKeys) } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift index 2d63a2a..aa45d61 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift @@ -12,10 +12,7 @@ import ValueCoding // MARK: - Persistable extension Persistable where - Self: NSCoding, - Self.MetadataType: ValueCoding, - Self.MetadataType.Coder: NSCoding, - Self.MetadataType.Coder.ValueType == Self.MetadataType { + Self: NSCoding { // Writing @@ -25,8 +22,13 @@ extension Persistable where - parameter transaction: a YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(transaction: WriteTransaction) -> Self { - return transaction.write(self) + public func write< + WriteTransaction, Metadata where + WriteTransaction: WriteTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { + return transaction.write((self, metadata)) } /** @@ -35,8 +37,13 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: the receiver. */ - public func write(connection: Connection) -> Self { - return connection.write(self) + public func write< + Connection, Metadata where + Connection: ConnectionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { + return connection.write((self, metadata)) } /** @@ -45,8 +52,13 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (Self -> Void)? = .None) { - return connection.asyncWrite(self, queue: queue, completion: completion) + public func asyncWrite< + Connection, Metadata where + Connection: ConnectionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { + return connection.asyncWrite((self, metadata), queue: queue, completion: completion) } /** @@ -55,17 +67,19 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.write(self) } + public func writeOperation< + Connection, Metadata where + Connection: ConnectionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> NSOperation { + return NSBlockOperation { connection.write((self, metadata)) } } } extension SequenceType where Generator.Element: Persistable, - Generator.Element: NSCoding, - Generator.Element.MetadataType: ValueCoding, - Generator.Element.MetadataType.Coder: NSCoding, - Generator.Element.MetadataType.Coder.ValueType == Generator.Element.MetadataType { + Generator.Element: NSCoding { /** Write the items using an existing transaction. @@ -73,8 +87,14 @@ extension SequenceType where - parameter transaction: a WriteTransactionType e.g. YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(transaction: WriteTransaction) -> [Generator.Element] { - return transaction.write(self) + public func write< + WriteTransaction, Metadata where + WriteTransaction: WriteTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return transaction.write(items) } /** @@ -83,8 +103,14 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: the receiver. */ - public func write(connection: Connection) -> [Generator.Element] { - return connection.write(self) + public func write< + Connection, Metadata where + Connection: ConnectionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return connection.write(items) } /** @@ -93,8 +119,14 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([Generator.Element] -> Void)? = .None) { - return connection.asyncWrite(self, queue: queue, completion: completion) + public func asyncWrite< + Connection, Metadata where + Connection: ConnectionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return connection.asyncWrite(items, queue: queue, completion: completion) } /** @@ -103,8 +135,14 @@ extension SequenceType where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.write(self) } + public func writeOperation< + Connection, Metadata where + Connection: ConnectionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> NSOperation { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return NSBlockOperation { connection.write(items) } } } @@ -112,48 +150,74 @@ extension SequenceType where extension Readable where ItemType: NSCoding, - ItemType: Persistable, - ItemType.MetadataType: ValueCoding, - ItemType.MetadataType.Coder: NSCoding, - ItemType.MetadataType.Coder.ValueType == ItemType.MetadataType { + ItemType: Persistable { - func inTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> ItemType? { + func inTransaction< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { return transaction.readAtIndex(index) } - func inTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> ItemType? { + func inTransactionAtIndex< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { return { self.inTransaction(transaction, atIndex: $0) } } - func atIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> ItemType? { + func atIndexInTransaction< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { return { self.inTransaction($0, atIndex: index) } } func atIndexesInTransaction< - Indexes where + Indexes, Metadata where Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [ItemType] { - let atIndex = inTransactionAtIndex - return { indexes.flatMap(atIndex($0)) } + Indexes.Generator.Element == YapDB.Index, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + return { indexes.flatMap(self.inTransactionAtIndex($0)) } } - func inTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> ItemType? { + func inTransaction< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { return inTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func inTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> ItemType? { + func inTransactionByKey< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { return { self.inTransaction(transaction, byKey: $0) } } - func byKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> ItemType? { + func byKeyInTransaction< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { return { self.inTransaction($0, byKey: key) } } - func byKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [ItemType] { - let byKey = inTransactionByKey + func byKeysInTransaction< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(byKey(transaction)) + return keys.flatMap(self.inTransactionByKey(transaction)) } } @@ -163,7 +227,11 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func atIndex(index: YapDB.Index) -> ItemType? { + public func atIndex< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (ItemType, Metadata?)? { return sync(atIndexInTransaction(index)) } @@ -174,9 +242,12 @@ extension Readable where - returns: an array of `ItemType` */ public func atIndexes< - Indexes where + Indexes, Metadata where Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> [ItemType] { + Indexes.Generator.Element == YapDB.Index, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(ItemType, Metadata?)] { return sync(atIndexesInTransaction(indexes)) } @@ -186,7 +257,11 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func byKey(key: String) -> ItemType? { + public func byKey< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(key: String) -> (ItemType, Metadata?)? { return sync(byKeyInTransaction(key)) } @@ -197,9 +272,12 @@ extension Readable where - returns: an array of `ItemType` */ public func byKeys< - Keys where + Keys, Metadata where Keys: SequenceType, - Keys.Generator.Element == String>(keys: Keys) -> [ItemType] { + Keys.Generator.Element == String, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(ItemType, Metadata?)] { return sync(byKeysInTransaction(Array(keys))) } @@ -208,7 +286,11 @@ extension Readable where - returns: an array of `ItemType` */ - public func all() -> [ItemType] { + public func all< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>() -> [(ItemType, Metadata?)] { return sync(byKeysInTransaction()) } @@ -218,11 +300,15 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func filterExisting(keys: [String]) -> (existing: [ItemType], missing: [String]) { - let existingInTransaction = byKeysInTransaction(keys) - return sync { transaction -> ([ItemType], [String]) in + public func filterExisting< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { + let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = byKeysInTransaction(keys) + return sync { transaction -> ([(ItemType, Metadata?)], [String]) in let existing = existingInTransaction(transaction) - let existingKeys = existing.map(keyForPersistable) + let existingKeys = existing.map {keyForPersistable($0.0)} let missingKeys = keys.filter { !existingKeys.contains($0) } return (existing, missingKeys) } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift index ceb3f47..5e2e458 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift @@ -14,8 +14,7 @@ import ValueCoding extension Persistable where Self: ValueCoding, Self.Coder: NSCoding, - Self.Coder.ValueType == Self, - Self.MetadataType: NSCoding { + Self.Coder.ValueType == Self { // Writing @@ -25,8 +24,11 @@ extension Persistable where - parameter transaction: a YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(transaction: WriteTransaction) -> Self { - return transaction.write(self) + public func write< + WriteTransaction, Metadata where + WriteTransaction: WriteTransactionType, + Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { + return transaction.write((self, metadata)) } /** @@ -35,8 +37,11 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: the receiver. */ - public func write(connection: Connection) -> Self { - return connection.write(self) + public func write< + Connection, Metadata where + Connection: ConnectionType, + Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { + return connection.write((self, metadata)) } /** @@ -45,8 +50,11 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (Self -> Void)? = .None) { - return connection.asyncWrite(self, queue: queue, completion: completion) + public func asyncWrite< + Connection, Metadata where + Connection: ConnectionType, + Metadata: NSCoding>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { + return connection.asyncWrite((self, metadata), queue: queue, completion: completion) } /** @@ -55,8 +63,11 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.write(self) } + public func writeOperation< + Connection, Metadata where + Connection: ConnectionType, + Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> NSOperation { + return NSBlockOperation { connection.write((self, metadata)) } } } @@ -64,8 +75,7 @@ extension SequenceType where Generator.Element: Persistable, Generator.Element: ValueCoding, Generator.Element.Coder: NSCoding, - Generator.Element.Coder.ValueType == Generator.Element, - Generator.Element.MetadataType: NSCoding { + Generator.Element.Coder.ValueType == Generator.Element { /** Write the items using an existing transaction. @@ -73,8 +83,12 @@ extension SequenceType where - parameter transaction: a WriteTransactionType e.g. YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(transaction: WriteTransaction) -> [Generator.Element] { - return transaction.write(self) + public func write< + WriteTransaction, Metadata where + WriteTransaction: WriteTransactionType, + Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return transaction.write(items) } /** @@ -83,8 +97,12 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: the receiver. */ - public func write(connection: Connection) -> [Generator.Element] { - return connection.write(self) + public func write< + Connection, Metadata where + Connection: ConnectionType, + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return connection.write(items) } /** @@ -93,8 +111,12 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([Generator.Element] -> Void)? = .None) { - return connection.asyncWrite(self, queue: queue, completion: completion) + public func asyncWrite< + Connection, Metadata where + Connection: ConnectionType, + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return connection.asyncWrite(items, queue: queue, completion: completion) } /** @@ -103,8 +125,12 @@ extension SequenceType where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.write(self) } + public func writeOperation< + Connection, Metadata where + Connection: ConnectionType, + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> NSOperation { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return NSBlockOperation { connection.write(items) } } } @@ -115,46 +141,44 @@ extension Readable where ItemType: ValueCoding, ItemType: Persistable, ItemType.Coder: NSCoding, - ItemType.Coder.ValueType == ItemType, - ItemType.MetadataType: NSCoding { + ItemType.Coder.ValueType == ItemType { - func inTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> ItemType? { + func inTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { return transaction.readAtIndex(index) } - func inTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> ItemType? { + func inTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { return { self.inTransaction(transaction, atIndex: $0) } } - func atIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> ItemType? { + func atIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { return { self.inTransaction($0, atIndex: index) } } func atIndexesInTransaction< - Indexes where + Indexes, Metadata where Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [ItemType] { - let atIndex = inTransactionAtIndex - return { indexes.flatMap(atIndex($0)) } + Indexes.Generator.Element == YapDB.Index, + Metadata: NSCoding>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + return { indexes.flatMap(self.inTransactionAtIndex($0)) } } - func inTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> ItemType? { + func inTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { return inTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func inTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> ItemType? { + func inTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { return { self.inTransaction(transaction, byKey: $0) } } - func byKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> ItemType? { + func byKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { return { self.inTransaction($0, byKey: key) } } - func byKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [ItemType] { - let byKey = inTransactionByKey + func byKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(byKey(transaction)) + return keys.flatMap(self.inTransactionByKey(transaction)) } } @@ -164,7 +188,7 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func atIndex(index: YapDB.Index) -> ItemType? { + public func atIndex(index: YapDB.Index) -> (ItemType, Metadata?)? { return sync(atIndexInTransaction(index)) } @@ -175,9 +199,10 @@ extension Readable where - returns: an array of `ItemType` */ public func atIndexes< - Indexes where + Indexes, Metadata where Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> [ItemType] { + Indexes.Generator.Element == YapDB.Index, + Metadata: NSCoding>(indexes: Indexes) -> [(ItemType, Metadata?)] { return sync(atIndexesInTransaction(indexes)) } @@ -187,7 +212,7 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func byKey(key: String) -> ItemType? { + public func byKey(key: String) -> (ItemType, Metadata?)? { return sync(byKeyInTransaction(key)) } @@ -198,9 +223,10 @@ extension Readable where - returns: an array of `ItemType` */ public func byKeys< - Keys where + Keys, Metadata where Keys: SequenceType, - Keys.Generator.Element == String>(keys: Keys) -> [ItemType] { + Keys.Generator.Element == String, + Metadata: NSCoding>(keys: Keys) -> [(ItemType, Metadata?)] { return sync(byKeysInTransaction(Array(keys))) } @@ -209,7 +235,7 @@ extension Readable where - returns: an array of `ItemType` */ - public func all() -> [ItemType] { + public func all() -> [(ItemType, Metadata?)] { return sync(byKeysInTransaction()) } @@ -219,11 +245,11 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func filterExisting(keys: [String]) -> (existing: [ItemType], missing: [String]) { - let existingInTransaction = byKeysInTransaction(keys) - return sync { transaction -> ([ItemType], [String]) in + public func filterExisting(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { + let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = byKeysInTransaction(keys) + return sync { transaction -> ([(ItemType, Metadata?)], [String]) in let existing = existingInTransaction(transaction) - let existingKeys = existing.map(keyForPersistable) + let existingKeys = existing.map {keyForPersistable($0.0)} let missingKeys = keys.filter { !existingKeys.contains($0) } return (existing, missingKeys) } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift index 5b7b0fd..69582c5 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift @@ -14,10 +14,7 @@ import ValueCoding extension Persistable where Self: ValueCoding, Self.Coder: NSCoding, - Self.Coder.ValueType == Self, - Self.MetadataType: ValueCoding, - Self.MetadataType.Coder: NSCoding, - Self.MetadataType.Coder.ValueType == Self.MetadataType { + Self.Coder.ValueType == Self { // Writing @@ -27,8 +24,13 @@ extension Persistable where - parameter transaction: a YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(transaction: WriteTransaction) -> Self { - return transaction.write(self) + public func write< + WriteTransaction, Metadata where + WriteTransaction: WriteTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { + return transaction.write((self, metadata)) } /** @@ -37,8 +39,13 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: the receiver. */ - public func write(connection: Connection) -> Self { - return connection.write(self) + public func write< + Connection, Metadata where + Connection: ConnectionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { + return connection.write((self, metadata)) } /** @@ -47,8 +54,13 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (Self -> Void)? = .None) { - return connection.asyncWrite(self, queue: queue, completion: completion) + public func asyncWrite< + Connection, Metadata where + Connection: ConnectionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { + return connection.asyncWrite((self, metadata), queue: queue, completion: completion) } /** @@ -57,8 +69,13 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.write(self) } + public func writeOperation< + Connection, Metadata where + Connection: ConnectionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> NSOperation { + return NSBlockOperation { connection.write((self, metadata)) } } } @@ -66,10 +83,7 @@ extension SequenceType where Generator.Element: Persistable, Generator.Element: ValueCoding, Generator.Element.Coder: NSCoding, - Generator.Element.Coder.ValueType == Generator.Element, - Generator.Element.MetadataType: ValueCoding, - Generator.Element.MetadataType.Coder: NSCoding, - Generator.Element.MetadataType.Coder.ValueType == Generator.Element.MetadataType { + Generator.Element.Coder.ValueType == Generator.Element { /** Write the items using an existing transaction. @@ -77,8 +91,14 @@ extension SequenceType where - parameter transaction: a WriteTransactionType e.g. YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(transaction: WriteTransaction) -> [Generator.Element] { - return transaction.write(self) + public func write< + WriteTransaction, Metadata where + WriteTransaction: WriteTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return transaction.write(items) } /** @@ -87,8 +107,14 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: the receiver. */ - public func write(connection: Connection) -> [Generator.Element] { - return connection.write(self) + public func write< + Connection, Metadata where + Connection: ConnectionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return connection.write(items) } /** @@ -97,8 +123,14 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([Generator.Element] -> Void)? = .None) { - return connection.asyncWrite(self, queue: queue, completion: completion) + public func asyncWrite< + Connection, Metadata where + Connection: ConnectionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return connection.asyncWrite(items, queue: queue, completion: completion) } /** @@ -107,8 +139,14 @@ extension SequenceType where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.write(self) } + public func writeOperation< + Connection, Metadata where + Connection: ConnectionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> NSOperation { + let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + return NSBlockOperation { connection.write(items) } } } @@ -118,48 +156,74 @@ extension Readable where ItemType: ValueCoding, ItemType: Persistable, ItemType.Coder: NSCoding, - ItemType.Coder.ValueType == ItemType, - ItemType.MetadataType: ValueCoding, - ItemType.MetadataType.Coder: NSCoding, - ItemType.MetadataType.Coder.ValueType == ItemType.MetadataType { + ItemType.Coder.ValueType == ItemType { - func inTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> ItemType? { + func inTransaction< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { return transaction.readAtIndex(index) } - func inTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> ItemType? { + func inTransactionAtIndex< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { return { self.inTransaction(transaction, atIndex: $0) } } - func atIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> ItemType? { + func atIndexInTransaction< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { return { self.inTransaction($0, atIndex: index) } } func atIndexesInTransaction< - Indexes where + Indexes, Metadata where Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [ItemType] { - let atIndex = inTransactionAtIndex - return { indexes.flatMap(atIndex($0)) } + Indexes.Generator.Element == YapDB.Index, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + return { indexes.flatMap(self.inTransactionAtIndex($0)) } } - func inTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> ItemType? { + func inTransaction< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { return inTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func inTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> ItemType? { + func inTransactionByKey< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { return { self.inTransaction(transaction, byKey: $0) } } - func byKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> ItemType? { + func byKeyInTransaction< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { return { self.inTransaction($0, byKey: key) } } - func byKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [ItemType] { - let byKey = inTransactionByKey + func byKeysInTransaction< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(byKey(transaction)) + return keys.flatMap(self.inTransactionByKey(transaction)) } } @@ -169,7 +233,11 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func atIndex(index: YapDB.Index) -> ItemType? { + public func atIndex< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (ItemType, Metadata?)? { return sync(atIndexInTransaction(index)) } @@ -180,9 +248,12 @@ extension Readable where - returns: an array of `ItemType` */ public func atIndexes< - Indexes where + Indexes, Metadata where Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> [ItemType] { + Indexes.Generator.Element == YapDB.Index, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(ItemType, Metadata?)] { return sync(atIndexesInTransaction(indexes)) } @@ -192,7 +263,11 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func byKey(key: String) -> ItemType? { + public func byKey< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(key: String) -> (ItemType, Metadata?)? { return sync(byKeyInTransaction(key)) } @@ -203,9 +278,12 @@ extension Readable where - returns: an array of `ItemType` */ public func byKeys< - Keys where + Keys, Metadata where Keys: SequenceType, - Keys.Generator.Element == String>(keys: Keys) -> [ItemType] { + Keys.Generator.Element == String, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(ItemType, Metadata?)] { return sync(byKeysInTransaction(Array(keys))) } @@ -214,7 +292,11 @@ extension Readable where - returns: an array of `ItemType` */ - public func all() -> [ItemType] { + public func all< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>() -> [(ItemType, Metadata?)] { return sync(byKeysInTransaction()) } @@ -224,11 +306,15 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func filterExisting(keys: [String]) -> (existing: [ItemType], missing: [String]) { - let existingInTransaction = byKeysInTransaction(keys) - return sync { transaction -> ([ItemType], [String]) in + public func filterExisting< + Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { + let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = byKeysInTransaction(keys) + return sync { transaction -> ([(ItemType, Metadata?)], [String]) in let existing = existingInTransaction(transaction) - let existingKeys = existing.map(keyForPersistable) + let existingKeys = existing.map {keyForPersistable($0.0)} let missingKeys = keys.filter { !existingKeys.contains($0) } return (existing, missingKeys) } From 10ec086907f9a2800ae7af10c366210fbfe6b232 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Fri, 9 Sep 2016 19:48:02 -0700 Subject: [PATCH 05/54] fix curried with metadata versions --- .../Curried_ObjectWithObjectMetadata.swift | 38 ++++++++------ .../Curried_ObjectWithValueMetadata.swift | 42 ++++++++++------ .../Curried_ValueWithObjectMetadata.swift | 38 ++++++++------ .../Curried_ValueWithValueMetadata.swift | 50 ++++++++++++------- 4 files changed, 104 insertions(+), 64 deletions(-) diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithObjectMetadata.swift index d763a90..a26adec 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithObjectMetadata.swift @@ -12,8 +12,7 @@ import ValueCoding // MARK: - Persistable extension Persistable where - Self: NSCoding, - Self.MetadataType: NSCoding { + Self: NSCoding { /** Returns a closure which, given a read transaction will return @@ -23,9 +22,10 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readAtIndex< - ReadTransaction where - ReadTransaction: ReadTransactionType>(index: YapDB.Index) -> ReadTransaction -> Self? { - return { $0.readAtIndex(index) } + ReadTransaction, Metadata where + ReadTransaction: ReadTransactionType, + Metadata: NSCoding>(index: YapDB.Index) -> ReadTransaction -> (Self, Metadata?)? { + return { $0.readAtIndex(index) } } /** @@ -36,11 +36,12 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readAtIndexes< - Indexes, ReadTransaction where + Indexes, ReadTransaction, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ReadTransaction: ReadTransactionType>(indexes: Indexes) -> ReadTransaction -> [Self] { - return { $0.readAtIndexes(indexes) } + ReadTransaction: ReadTransactionType, + Metadata: NSCoding>(indexes: Indexes) -> ReadTransaction -> [(Self, Metadata?)] { + return { $0.readAtIndexes(indexes) } } /** @@ -51,9 +52,10 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readByKey< - ReadTransaction where - ReadTransaction: ReadTransactionType>(key: String) -> ReadTransaction -> Self? { - return { $0.readByKey(key) } + ReadTransaction, Metadata where + ReadTransaction: ReadTransactionType, + Metadata: NSCoding>(key: String) -> ReadTransaction -> (Self, Metadata?)? { + return { $0.readByKey(key) } } /** @@ -64,11 +66,12 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readByKeys< - Keys, ReadTransaction where + Keys, ReadTransaction, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - ReadTransaction: ReadTransactionType>(keys: Keys) -> ReadTransaction -> [Self] { - return { $0.readAtIndexes(Self.indexesWithKeys(keys)) } + ReadTransaction: ReadTransactionType, + Metadata: NSCoding>(keys: Keys) -> ReadTransaction -> [(Self, Metadata?)] { + return { $0.readAtIndexes(Self.indexesWithKeys(keys)) } } /** @@ -78,7 +81,10 @@ extension Persistable where - warning: Be aware that this will capure `self`. - returns: a (WriteTransaction) -> Self closure */ - public func write() -> WriteTransaction -> Self { - return { $0.write(self) } + public func write< + WriteTransaction, Metadata where + WriteTransaction: WriteTransactionType, + Metadata: NSCoding>(metadata: Metadata? = nil) -> WriteTransaction -> (Self, Metadata?) { + return { $0.write((self, metadata)) } } } diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithValueMetadata.swift index 6690f2f..c6fc8c7 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithValueMetadata.swift @@ -12,10 +12,7 @@ import ValueCoding // MARK: - Persistable extension Persistable where - Self: NSCoding, - Self.MetadataType: ValueCoding, - Self.MetadataType.Coder: NSCoding, - Self.MetadataType.Coder.ValueType == Self.MetadataType { + Self: NSCoding { /** Returns a closure which, given a read transaction will return @@ -25,8 +22,11 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readAtIndex< - ReadTransaction where - ReadTransaction: ReadTransactionType>(index: YapDB.Index) -> ReadTransaction -> Self? { + ReadTransaction, Metadata where + ReadTransaction: ReadTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> ReadTransaction -> (Self, Metadata?)? { return { $0.readAtIndex(index) } } @@ -38,10 +38,13 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readAtIndexes< - Indexes, ReadTransaction where + Indexes, ReadTransaction, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ReadTransaction: ReadTransactionType>(indexes: Indexes) -> ReadTransaction -> [Self] { + ReadTransaction: ReadTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> ReadTransaction -> [(Self, Metadata?)] { return { $0.readAtIndexes(indexes) } } @@ -53,8 +56,11 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readByKey< - ReadTransaction where - ReadTransaction: ReadTransactionType>(key: String) -> ReadTransaction -> Self? { + ReadTransaction, Metadata where + ReadTransaction: ReadTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(key: String) -> ReadTransaction -> (Self, Metadata?)? { return { $0.readByKey(key) } } @@ -66,10 +72,13 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readByKeys< - Keys, ReadTransaction where + Keys, ReadTransaction, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - ReadTransaction: ReadTransactionType>(keys: Keys) -> ReadTransaction -> [Self] { + ReadTransaction: ReadTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> ReadTransaction -> [(Self, Metadata?)] { return { $0.readAtIndexes(Self.indexesWithKeys(keys)) } } @@ -80,7 +89,12 @@ extension Persistable where - warning: Be aware that this will capure `self`. - returns: a (WriteTransaction) -> Self closure */ - public func write() -> WriteTransaction -> Self { - return { $0.write(self) } + public func write< + WriteTransaction, Metadata where + WriteTransaction: WriteTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(metadata: Metadata? = nil) -> WriteTransaction -> (Self, Metadata?) { + return { $0.write((self, metadata)) } } } diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithObjectMetadata.swift index 6245a38..d2e925c 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithObjectMetadata.swift @@ -14,8 +14,7 @@ import ValueCoding extension Persistable where Self: ValueCoding, Self.Coder: NSCoding, - Self.Coder.ValueType == Self, - Self.MetadataType: NSCoding { + Self.Coder.ValueType == Self { /** Returns a closure which, given a read transaction will return @@ -25,9 +24,10 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readAtIndex< - ReadTransaction where - ReadTransaction: ReadTransactionType>(index: YapDB.Index) -> ReadTransaction -> Self? { - return { $0.readAtIndex(index) } + ReadTransaction, Metadata where + ReadTransaction: ReadTransactionType, + Metadata: NSCoding>(index: YapDB.Index) -> ReadTransaction -> (Self, Metadata?)? { + return { $0.readAtIndex(index) } } /** @@ -38,11 +38,12 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readAtIndexes< - Indexes, ReadTransaction where + Indexes, ReadTransaction, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ReadTransaction: ReadTransactionType>(indexes: Indexes) -> ReadTransaction -> [Self] { - return { $0.readAtIndexes(indexes) } + ReadTransaction: ReadTransactionType, + Metadata: NSCoding>(indexes: Indexes) -> ReadTransaction -> [(Self, Metadata?)] { + return { $0.readAtIndexes(indexes) } } /** @@ -53,9 +54,10 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readByKey< - ReadTransaction where - ReadTransaction: ReadTransactionType>(key: String) -> ReadTransaction -> Self? { - return { $0.readByKey(key) } + ReadTransaction, Metadata where + ReadTransaction: ReadTransactionType, + Metadata: NSCoding>(key: String) -> ReadTransaction -> (Self, Metadata?)? { + return { $0.readByKey(key) } } /** @@ -66,11 +68,12 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readByKeys< - Keys, ReadTransaction where + Keys, ReadTransaction, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - ReadTransaction: ReadTransactionType>(keys: Keys) -> ReadTransaction -> [Self] { - return { $0.readAtIndexes(Self.indexesWithKeys(keys)) } + ReadTransaction: ReadTransactionType, + Metadata: NSCoding>(keys: Keys) -> ReadTransaction -> [(Self, Metadata?)] { + return { $0.readAtIndexes(Self.indexesWithKeys(keys)) } } /** @@ -80,7 +83,10 @@ extension Persistable where - warning: Be aware that this will capure `self`. - returns: a (WriteTransaction) -> Self closure */ - public func write() -> WriteTransaction -> Self { - return { $0.write(self) } + public func write< + WriteTransaction, Metadata where + WriteTransaction: WriteTransactionType, + Metadata: NSCoding>(metadata: Metadata? = nil) -> WriteTransaction -> (Self, Metadata?) { + return { $0.write((self, metadata)) } } } diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithValueMetadata.swift index c59f580..0e0b267 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithValueMetadata.swift @@ -14,10 +14,7 @@ import ValueCoding extension Persistable where Self: ValueCoding, Self.Coder: NSCoding, - Self.Coder.ValueType == Self, - Self.MetadataType: ValueCoding, - Self.MetadataType.Coder: NSCoding, - Self.MetadataType.Coder.ValueType == Self.MetadataType { + Self.Coder.ValueType == Self { /** Returns a closure which, given a read transaction will return @@ -27,9 +24,12 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readAtIndex< - ReadTransaction where - ReadTransaction: ReadTransactionType>(index: YapDB.Index) -> ReadTransaction -> Self? { - return { $0.readAtIndex(index) } + ReadTransaction, Metadata where + ReadTransaction: ReadTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> ReadTransaction -> (Self, Metadata?)? { + return { $0.readAtIndex(index) } } /** @@ -40,11 +40,14 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readAtIndexes< - Indexes, ReadTransaction where + Indexes, ReadTransaction, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - ReadTransaction: ReadTransactionType>(indexes: Indexes) -> ReadTransaction -> [Self] { - return { $0.readAtIndexes(indexes) } + ReadTransaction: ReadTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> ReadTransaction -> [(Self, Metadata?)] { + return { $0.readAtIndexes(indexes) } } /** @@ -55,9 +58,12 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readByKey< - ReadTransaction where - ReadTransaction: ReadTransactionType>(key: String) -> ReadTransaction -> Self? { - return { $0.readByKey(key) } + ReadTransaction, Metadata where + ReadTransaction: ReadTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(key: String) -> ReadTransaction -> (Self, Metadata?)? { + return { $0.readByKey(key) } } /** @@ -68,11 +74,14 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readByKeys< - Keys, ReadTransaction where + Keys, ReadTransaction, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - ReadTransaction: ReadTransactionType>(keys: Keys) -> ReadTransaction -> [Self] { - return { $0.readAtIndexes(Self.indexesWithKeys(keys)) } + ReadTransaction: ReadTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> ReadTransaction -> [(Self, Metadata?)] { + return { $0.readAtIndexes(Self.indexesWithKeys(keys)) } } /** @@ -82,7 +91,12 @@ extension Persistable where - warning: Be aware that this will capure `self`. - returns: a (WriteTransaction) -> Self closure */ - public func write() -> WriteTransaction -> Self { - return { $0.write(self) } + public func write< + WriteTransaction, Metadata where + WriteTransaction: WriteTransactionType, + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata>(metadata: Metadata? = nil) -> WriteTransaction -> (Self, Metadata?) { + return { $0.write((self, metadata)) } } } From 7fb0d329f3b72f56f0cb6d029dd0b13fa83bc986 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Fri, 9 Sep 2016 19:48:28 -0700 Subject: [PATCH 06/54] give metadata parameters default values in write methods --- .../Persistable_ObjectWithObjectMetadata.swift | 16 ++++++++-------- .../Persistable_ObjectWithValueMetadata.swift | 16 ++++++++-------- .../Persistable_ValueWithObjectMetadata.swift | 16 ++++++++-------- .../Persistable_ValueWithValueMetadata.swift | 16 ++++++++-------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift index 49f9770..294be2b 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift @@ -24,7 +24,7 @@ extension Persistable where public func write< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { + Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata? = nil) -> (Self, Metadata?) { return transaction.write((self, metadata)) } @@ -37,7 +37,7 @@ extension Persistable where public func write< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { + Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil) -> (Self, Metadata?) { return connection.write((self, metadata)) } @@ -50,7 +50,7 @@ extension Persistable where public func asyncWrite< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { + Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { return connection.asyncWrite((self, metadata), queue: queue, completion: completion) } @@ -63,7 +63,7 @@ extension Persistable where public func writeOperation< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> NSOperation { + Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil) -> NSOperation { return NSBlockOperation { connection.write((self, metadata)) } } } @@ -81,7 +81,7 @@ extension SequenceType where public func write< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return transaction.write(items) } @@ -95,7 +95,7 @@ extension SequenceType where public func write< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return connection.write(items) } @@ -109,7 +109,7 @@ extension SequenceType where public func asyncWrite< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return connection.asyncWrite(items, queue: queue, completion: completion) } @@ -123,7 +123,7 @@ extension SequenceType where public func writeOperation< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> NSOperation { + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return NSBlockOperation { connection.write(items) } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift index aa45d61..6270433 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift @@ -27,7 +27,7 @@ extension Persistable where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata? = nil) -> (Self, Metadata?) { return transaction.write((self, metadata)) } @@ -42,7 +42,7 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil) -> (Self, Metadata?) { return connection.write((self, metadata)) } @@ -57,7 +57,7 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { return connection.asyncWrite((self, metadata), queue: queue, completion: completion) } @@ -72,7 +72,7 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> NSOperation { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil) -> NSOperation { return NSBlockOperation { connection.write((self, metadata)) } } } @@ -92,7 +92,7 @@ extension SequenceType where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return transaction.write(items) } @@ -108,7 +108,7 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return connection.write(items) } @@ -124,7 +124,7 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return connection.asyncWrite(items, queue: queue, completion: completion) } @@ -140,7 +140,7 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> NSOperation { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return NSBlockOperation { connection.write(items) } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift index 5e2e458..fb398eb 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift @@ -27,7 +27,7 @@ extension Persistable where public func write< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { + Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata? = nil) -> (Self, Metadata?) { return transaction.write((self, metadata)) } @@ -40,7 +40,7 @@ extension Persistable where public func write< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { + Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil) -> (Self, Metadata?) { return connection.write((self, metadata)) } @@ -53,7 +53,7 @@ extension Persistable where public func asyncWrite< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { + Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { return connection.asyncWrite((self, metadata), queue: queue, completion: completion) } @@ -66,7 +66,7 @@ extension Persistable where public func writeOperation< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> NSOperation { + Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil) -> NSOperation { return NSBlockOperation { connection.write((self, metadata)) } } } @@ -86,7 +86,7 @@ extension SequenceType where public func write< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return transaction.write(items) } @@ -100,7 +100,7 @@ extension SequenceType where public func write< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return connection.write(items) } @@ -114,7 +114,7 @@ extension SequenceType where public func asyncWrite< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return connection.asyncWrite(items, queue: queue, completion: completion) } @@ -128,7 +128,7 @@ extension SequenceType where public func writeOperation< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> NSOperation { + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return NSBlockOperation { connection.write(items) } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift index 69582c5..689bd3c 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift @@ -29,7 +29,7 @@ extension Persistable where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata? = nil) -> (Self, Metadata?) { return transaction.write((self, metadata)) } @@ -44,7 +44,7 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil) -> (Self, Metadata?) { return connection.write((self, metadata)) } @@ -59,7 +59,7 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { return connection.asyncWrite((self, metadata), queue: queue, completion: completion) } @@ -74,7 +74,7 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> NSOperation { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil) -> NSOperation { return NSBlockOperation { connection.write((self, metadata)) } } } @@ -96,7 +96,7 @@ extension SequenceType where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return transaction.write(items) } @@ -112,7 +112,7 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return connection.write(items) } @@ -128,7 +128,7 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return connection.asyncWrite(items, queue: queue, completion: completion) } @@ -144,7 +144,7 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> NSOperation { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { let items = enumerate().map({ (index, element) in (element, metadata[index]) }) return NSBlockOperation { connection.write(items) } } From cf71843ee891a9c8cf72030c4e736050a7962cce Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Fri, 9 Sep 2016 19:49:36 -0700 Subject: [PATCH 07/54] remove commented metadata portions of Persistable protocol --- .../Shared/YapDatabaseExtensions.swift | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift b/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift index 20b84cf..e7ea5c9 100644 --- a/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift +++ b/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift @@ -181,15 +181,9 @@ defined in this framework. It assumes that all instances of a type are stored in the same YapDatabase collection. */ public protocol Persistable: Identifiable { -// -// /// The nested type of the metadata. Defaults to Void. -// associatedtype MetadataType /// The YapDatabase collection name the type is stored in. static var collection: String { get } -// -// /// A metadata which is set when reading, and get when writing. -// var metadata: MetadataType? { get set } } extension Persistable { @@ -222,15 +216,6 @@ extension Persistable { return Set(keys).map { YapDB.Index(collection: collection, key: $0) } } - /** - Default metadata property. Implement this to re-define your - own MetadataType. - */ - public var metadata: Void? { - get { return .None } - set { } - } - /** Convenience computed property to get the key for a persistable, which is just the identifier's description. From 2987602feac3a0d6c7611fe52ec8f898471f1250 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Fri, 9 Sep 2016 21:07:21 -0700 Subject: [PATCH 08/54] update comments --- .../Persistable/Persistable_AnyWithObjectMetadata.swift | 4 ++-- .../Shared/Persistable/Persistable_AnyWithValueMetadata.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithObjectMetadata.swift index 6208e01..fbe08ed 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithObjectMetadata.swift @@ -38,7 +38,7 @@ extension Readable where Reads the metadata at a given index. - parameter index: a YapDB.Index - - returns: an optional `ItemType.MetadataType` + - returns: an optional `Metadata` */ public func metadataAtIndex< Metadata where @@ -50,7 +50,7 @@ extension Readable where Reads the metadata at the indexes. - parameter indexes: a SequenceType of YapDB.Index values - - returns: an array of `ItemType.MetadataType` + - returns: an array of `Metadata` */ public func metadataAtIndexes< Indexes, Metadata where diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithValueMetadata.swift index 1011383..9147903 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_AnyWithValueMetadata.swift @@ -52,7 +52,7 @@ extension Readable where Reads the metadata at a given index. - parameter index: a YapDB.Index - - returns: an optional `ItemType.MetadataType` + - returns: an optional `Metadata` */ public func metadataAtIndex< Metadata where @@ -66,7 +66,7 @@ extension Readable where Reads the metadata at the indexes. - parameter indexes: a SequenceType of YapDB.Index values - - returns: an array of `ItemType.MetadataType` + - returns: an array of `Metadata` */ public func metadataAtIndexes< Indexes, Metadata where From 8c7c4c7fa188b5ae91cdea67a700d0fc80a65657 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Fri, 9 Sep 2016 21:57:57 -0700 Subject: [PATCH 09/54] add zipToWrite function that creates a list of tuples - hopefully this can be removed after a refactor later --- .../Persistable_ObjectWithObjectMetadata.swift | 8 ++++---- .../Persistable_ObjectWithValueMetadata.swift | 8 ++++---- .../Persistable_ValueWithObjectMetadata.swift | 8 ++++---- .../Persistable_ValueWithValueMetadata.swift | 8 ++++---- .../Shared/YapDatabaseExtensions.swift | 10 ++++++++++ 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift index 294be2b..a6c7180 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift @@ -82,7 +82,7 @@ extension SequenceType where WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return transaction.write(items) } @@ -96,7 +96,7 @@ extension SequenceType where Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return connection.write(items) } @@ -110,7 +110,7 @@ extension SequenceType where Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return connection.asyncWrite(items, queue: queue, completion: completion) } @@ -124,7 +124,7 @@ extension SequenceType where Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return NSBlockOperation { connection.write(items) } } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift index 6270433..7642ba8 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift @@ -93,7 +93,7 @@ extension SequenceType where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return transaction.write(items) } @@ -109,7 +109,7 @@ extension SequenceType where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return connection.write(items) } @@ -125,7 +125,7 @@ extension SequenceType where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return connection.asyncWrite(items, queue: queue, completion: completion) } @@ -141,7 +141,7 @@ extension SequenceType where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return NSBlockOperation { connection.write(items) } } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift index fb398eb..9d2703c 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift @@ -87,7 +87,7 @@ extension SequenceType where WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return transaction.write(items) } @@ -101,7 +101,7 @@ extension SequenceType where Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return connection.write(items) } @@ -115,7 +115,7 @@ extension SequenceType where Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return connection.asyncWrite(items, queue: queue, completion: completion) } @@ -129,7 +129,7 @@ extension SequenceType where Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return NSBlockOperation { connection.write(items) } } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift index 689bd3c..db778c1 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift @@ -97,7 +97,7 @@ extension SequenceType where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return transaction.write(items) } @@ -113,7 +113,7 @@ extension SequenceType where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return connection.write(items) } @@ -129,7 +129,7 @@ extension SequenceType where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return connection.asyncWrite(items, queue: queue, completion: completion) } @@ -145,7 +145,7 @@ extension SequenceType where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { - let items = enumerate().map({ (index, element) in (element, metadata[index]) }) + let items = zipToWrite(self, metadata) return NSBlockOperation { connection.write(items) } } } diff --git a/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift b/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift index e7ea5c9..aa3a1b8 100644 --- a/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift +++ b/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift @@ -119,6 +119,16 @@ public struct YapDB { } } +public func zipToWrite< + Value, Values, Metadata, Metadatas where + Values: SequenceType, + Values.Generator.Element == Value, + Metadatas: SequenceType, + Metadatas.Generator.Element == Metadata + >(values: Values, _ metadatas: Metadatas) -> [(Value, Metadata)] { + return zip(values, metadatas).map { ($0, $1) } +} + extension YapDB { /** From 756a308e30c66794fe83ce56a14be9ec770640b6 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Sat, 10 Sep 2016 12:34:15 -0700 Subject: [PATCH 10/54] =?UTF-8?q?add=20=E2=80=9CWithMetadata=E2=80=9D=20to?= =?UTF-8?q?=20API=20that=20reads=20and=20writes=20items=20and=20their=20me?= =?UTF-8?q?tadata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Curried_ObjectWithObjectMetadata.swift | 20 ++--- .../Curried_ObjectWithValueMetadata.swift | 20 ++--- .../Curried_ValueWithObjectMetadata.swift | 20 ++--- .../Curried_ValueWithValueMetadata.swift | 20 ++--- .../Functional_ObjectWithObjectMetadata.swift | 60 ++++++------- .../Functional_ObjectWithValueMetadata.swift | 60 ++++++------- .../Functional_ValueWIthObjectMetadata.swift | 60 ++++++------- .../Functional_ValueWIthValueMetadata.swift | 60 ++++++------- ...Persistable_ObjectWithObjectMetadata.swift | 88 +++++++++---------- .../Persistable_ObjectWithValueMetadata.swift | 88 +++++++++---------- .../Persistable_ValueWithObjectMetadata.swift | 88 +++++++++---------- .../Persistable_ValueWithValueMetadata.swift | 88 +++++++++---------- 12 files changed, 336 insertions(+), 336 deletions(-) diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithObjectMetadata.swift index a26adec..333c42e 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithObjectMetadata.swift @@ -21,11 +21,11 @@ extension Persistable where - parameter index: a YapDB.Index - returns: a (ReadTransaction) -> Self? closure. */ - public static func readAtIndex< + public static func readWithMetadataAtIndex< ReadTransaction, Metadata where ReadTransaction: ReadTransactionType, Metadata: NSCoding>(index: YapDB.Index) -> ReadTransaction -> (Self, Metadata?)? { - return { $0.readAtIndex(index) } + return { $0.readWithMetadataAtIndex(index) } } /** @@ -35,13 +35,13 @@ extension Persistable where - parameter indexes: a SequenceType of YapDB.Index values - returns: a (ReadTransaction) -> [Self] closure. */ - public static func readAtIndexes< + public static func readWithMetadataAtIndexes< Indexes, ReadTransaction, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, ReadTransaction: ReadTransactionType, Metadata: NSCoding>(indexes: Indexes) -> ReadTransaction -> [(Self, Metadata?)] { - return { $0.readAtIndexes(indexes) } + return { $0.readWithMetadataAtIndexes(indexes) } } /** @@ -51,11 +51,11 @@ extension Persistable where - parameter key: a String - returns: a (ReadTransaction) -> Self? closure. */ - public static func readByKey< + public static func readWithMetadataByKey< ReadTransaction, Metadata where ReadTransaction: ReadTransactionType, Metadata: NSCoding>(key: String) -> ReadTransaction -> (Self, Metadata?)? { - return { $0.readByKey(key) } + return { $0.readWithMetadataByKey(key) } } /** @@ -65,13 +65,13 @@ extension Persistable where - parameter keys: a SequenceType of String values - returns: a (ReadTransaction) -> [Self] closure. */ - public static func readByKeys< + public static func readWithMetadataByKeys< Keys, ReadTransaction, Metadata where Keys: SequenceType, Keys.Generator.Element == String, ReadTransaction: ReadTransactionType, Metadata: NSCoding>(keys: Keys) -> ReadTransaction -> [(Self, Metadata?)] { - return { $0.readAtIndexes(Self.indexesWithKeys(keys)) } + return { $0.readWithMetadataAtIndexes(Self.indexesWithKeys(keys)) } } /** @@ -81,10 +81,10 @@ extension Persistable where - warning: Be aware that this will capure `self`. - returns: a (WriteTransaction) -> Self closure */ - public func write< + public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: NSCoding>(metadata: Metadata? = nil) -> WriteTransaction -> (Self, Metadata?) { - return { $0.write((self, metadata)) } + return { $0.writeWithMetadata((self, metadata)) } } } diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithValueMetadata.swift index c6fc8c7..b9b29a4 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithValueMetadata.swift @@ -21,13 +21,13 @@ extension Persistable where - parameter index: a YapDB.Index - returns: a (ReadTransaction) -> Self? closure. */ - public static func readAtIndex< + public static func readWithMetadataAtIndex< ReadTransaction, Metadata where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> ReadTransaction -> (Self, Metadata?)? { - return { $0.readAtIndex(index) } + return { $0.readWithMetadataAtIndex(index) } } /** @@ -37,7 +37,7 @@ extension Persistable where - parameter indexes: a SequenceType of YapDB.Index values - returns: a (ReadTransaction) -> [Self] closure. */ - public static func readAtIndexes< + public static func readWithMetadataAtIndexes< Indexes, ReadTransaction, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, @@ -45,7 +45,7 @@ extension Persistable where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> ReadTransaction -> [(Self, Metadata?)] { - return { $0.readAtIndexes(indexes) } + return { $0.readWithMetadataAtIndexes(indexes) } } /** @@ -55,13 +55,13 @@ extension Persistable where - parameter key: a String - returns: a (ReadTransaction) -> Self? closure. */ - public static func readByKey< + public static func readWithMetadataByKey< ReadTransaction, Metadata where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(key: String) -> ReadTransaction -> (Self, Metadata?)? { - return { $0.readByKey(key) } + return { $0.readWithMetadataByKey(key) } } /** @@ -71,7 +71,7 @@ extension Persistable where - parameter keys: a SequenceType of String values - returns: a (ReadTransaction) -> [Self] closure. */ - public static func readByKeys< + public static func readWithMetadataByKeys< Keys, ReadTransaction, Metadata where Keys: SequenceType, Keys.Generator.Element == String, @@ -79,7 +79,7 @@ extension Persistable where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(keys: Keys) -> ReadTransaction -> [(Self, Metadata?)] { - return { $0.readAtIndexes(Self.indexesWithKeys(keys)) } + return { $0.readWithMetadataAtIndexes(Self.indexesWithKeys(keys)) } } /** @@ -89,12 +89,12 @@ extension Persistable where - warning: Be aware that this will capure `self`. - returns: a (WriteTransaction) -> Self closure */ - public func write< + public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(metadata: Metadata? = nil) -> WriteTransaction -> (Self, Metadata?) { - return { $0.write((self, metadata)) } + return { $0.writeWithMetadata((self, metadata)) } } } diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithObjectMetadata.swift index d2e925c..c4c86bd 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithObjectMetadata.swift @@ -23,11 +23,11 @@ extension Persistable where - parameter index: a YapDB.Index - returns: a (ReadTransaction) -> Self? closure. */ - public static func readAtIndex< + public static func readWithMetadataAtIndex< ReadTransaction, Metadata where ReadTransaction: ReadTransactionType, Metadata: NSCoding>(index: YapDB.Index) -> ReadTransaction -> (Self, Metadata?)? { - return { $0.readAtIndex(index) } + return { $0.readWithMetadataAtIndex(index) } } /** @@ -37,13 +37,13 @@ extension Persistable where - parameter indexes: a SequenceType of YapDB.Index values - returns: a (ReadTransaction) -> [Self] closure. */ - public static func readAtIndexes< + public static func readWithMetadataAtIndexes< Indexes, ReadTransaction, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, ReadTransaction: ReadTransactionType, Metadata: NSCoding>(indexes: Indexes) -> ReadTransaction -> [(Self, Metadata?)] { - return { $0.readAtIndexes(indexes) } + return { $0.readWithMetadataAtIndexes(indexes) } } /** @@ -53,11 +53,11 @@ extension Persistable where - parameter key: a String - returns: a (ReadTransaction) -> Self? closure. */ - public static func readByKey< + public static func readWithMetadataByKey< ReadTransaction, Metadata where ReadTransaction: ReadTransactionType, Metadata: NSCoding>(key: String) -> ReadTransaction -> (Self, Metadata?)? { - return { $0.readByKey(key) } + return { $0.readWithMetadataByKey(key) } } /** @@ -67,13 +67,13 @@ extension Persistable where - parameter keys: a SequenceType of String values - returns: a (ReadTransaction) -> [Self] closure. */ - public static func readByKeys< + public static func readWithMetadataByKeys< Keys, ReadTransaction, Metadata where Keys: SequenceType, Keys.Generator.Element == String, ReadTransaction: ReadTransactionType, Metadata: NSCoding>(keys: Keys) -> ReadTransaction -> [(Self, Metadata?)] { - return { $0.readAtIndexes(Self.indexesWithKeys(keys)) } + return { $0.readWithMetadataAtIndexes(Self.indexesWithKeys(keys)) } } /** @@ -83,10 +83,10 @@ extension Persistable where - warning: Be aware that this will capure `self`. - returns: a (WriteTransaction) -> Self closure */ - public func write< + public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: NSCoding>(metadata: Metadata? = nil) -> WriteTransaction -> (Self, Metadata?) { - return { $0.write((self, metadata)) } + return { $0.writeWithMetadata((self, metadata)) } } } diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithValueMetadata.swift index 0e0b267..a3e59fe 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithValueMetadata.swift @@ -23,13 +23,13 @@ extension Persistable where - parameter index: a YapDB.Index - returns: a (ReadTransaction) -> Self? closure. */ - public static func readAtIndex< + public static func readWithMetadataAtIndex< ReadTransaction, Metadata where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> ReadTransaction -> (Self, Metadata?)? { - return { $0.readAtIndex(index) } + return { $0.readWithMetadataAtIndex(index) } } /** @@ -39,7 +39,7 @@ extension Persistable where - parameter indexes: a SequenceType of YapDB.Index values - returns: a (ReadTransaction) -> [Self] closure. */ - public static func readAtIndexes< + public static func readWithMetadataAtIndexes< Indexes, ReadTransaction, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, @@ -47,7 +47,7 @@ extension Persistable where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> ReadTransaction -> [(Self, Metadata?)] { - return { $0.readAtIndexes(indexes) } + return { $0.readWithMetadataAtIndexes(indexes) } } /** @@ -57,13 +57,13 @@ extension Persistable where - parameter key: a String - returns: a (ReadTransaction) -> Self? closure. */ - public static func readByKey< + public static func readWithMetadataByKey< ReadTransaction, Metadata where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(key: String) -> ReadTransaction -> (Self, Metadata?)? { - return { $0.readByKey(key) } + return { $0.readWithMetadataByKey(key) } } /** @@ -73,7 +73,7 @@ extension Persistable where - parameter keys: a SequenceType of String values - returns: a (ReadTransaction) -> [Self] closure. */ - public static func readByKeys< + public static func readWithMetadataByKeys< Keys, ReadTransaction, Metadata where Keys: SequenceType, Keys.Generator.Element == String, @@ -81,7 +81,7 @@ extension Persistable where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(keys: Keys) -> ReadTransaction -> [(Self, Metadata?)] { - return { $0.readAtIndexes(Self.indexesWithKeys(keys)) } + return { $0.readWithMetadataAtIndexes(Self.indexesWithKeys(keys)) } } /** @@ -91,12 +91,12 @@ extension Persistable where - warning: Be aware that this will capure `self`. - returns: a (WriteTransaction) -> Self closure */ - public func write< + public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(metadata: Metadata? = nil) -> WriteTransaction -> (Self, Metadata?) { - return { $0.write((self, metadata)) } + return { $0.writeWithMetadata((self, metadata)) } } } diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithObjectMetadata.swift index 7eff7f9..eb92925 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithObjectMetadata.swift @@ -20,7 +20,7 @@ extension ReadTransactionType { - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func readAtIndex< + public func readWithMetadataAtIndex< Object, Metadata where Object: Persistable, Object: NSCoding, @@ -36,7 +36,7 @@ extension ReadTransactionType { - parameter indexes: a SequenceType of YapDB.Index values - returns: an array of `ItemType` */ - public func readAtIndexes< + public func readWithMetadataAtIndexes< Indexes, Object, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, @@ -44,7 +44,7 @@ extension ReadTransactionType { Object: NSCoding, Metadata: NSCoding>(indexes: Indexes) -> [(Object, Metadata?)] { // FIXME: using flatMap means the output length need not match the input length - return indexes.flatMap(readAtIndex) + return indexes.flatMap(readWithMetadataAtIndex) } /** @@ -53,12 +53,12 @@ extension ReadTransactionType { - parameter key: a String - returns: an optional `ItemType` */ - public func readByKey< + public func readWithMetadataByKey< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: NSCoding>(key: String) -> (Object, Metadata?)? { - return readAtIndex(Object.indexWithKey(key)) + return readWithMetadataAtIndex(Object.indexWithKey(key)) } /** @@ -67,14 +67,14 @@ extension ReadTransactionType { - parameter keys: a SequenceType of String values - returns: an array of `ItemType` */ - public func readByKeys< + public func readWithMetadataByKeys< Keys, Object, Metadata where Keys: SequenceType, Keys.Generator.Element == String, Object: Persistable, Object: NSCoding, Metadata: NSCoding>(keys: Keys) -> [(Object, Metadata?)] { - return readAtIndexes(Object.indexesWithKeys(keys)) + return readWithMetadataAtIndexes(Object.indexesWithKeys(keys)) } /** @@ -82,12 +82,12 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ - public func readAll< + public func readWithMetadataAll< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: NSCoding>() -> [(Object, Metadata?)] { - return readByKeys(keysInCollection(Object.collection)) + return readWithMetadataByKeys(keysInCollection(Object.collection)) } } @@ -99,12 +99,12 @@ extension ConnectionType { - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func readAtIndex< + public func readWithMetadataAtIndex< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: NSCoding>(index: YapDB.Index) -> (Object, Metadata?)? { - return read { $0.readAtIndex(index) } + return read { $0.readWithMetadataAtIndex(index) } } /** @@ -113,14 +113,14 @@ extension ConnectionType { - parameter indexes: a SequenceType of YapDB.Index values - returns: an array of `ItemType` */ - public func readAtIndexes< + public func readWithMetadataAtIndexes< Indexes, Object, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, Object: Persistable, Object: NSCoding, Metadata: NSCoding>(indexes: Indexes) -> [(Object, Metadata?)] { - return read { $0.readAtIndexes(indexes) } + return read { $0.readWithMetadataAtIndexes(indexes) } } /** @@ -129,12 +129,12 @@ extension ConnectionType { - parameter key: a String - returns: an optional `ItemType` */ - public func readByKey< + public func readWithMetadataByKey< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: NSCoding>(key: String) -> (Object, Metadata?)? { - return readAtIndex(Object.indexWithKey(key)) + return readWithMetadataAtIndex(Object.indexWithKey(key)) } /** @@ -143,14 +143,14 @@ extension ConnectionType { - parameter keys: a SequenceType of String values - returns: an array of `ItemType` */ - public func readByKeys< + public func readWithMetadataByKeys< Keys, Object, Metadata where Keys: SequenceType, Keys.Generator.Element == String, Object: Persistable, Object: NSCoding, Metadata: NSCoding>(keys: Keys) -> [(Object, Metadata?)] { - return readAtIndexes(Object.indexesWithKeys(keys)) + return readWithMetadataAtIndexes(Object.indexesWithKeys(keys)) } /** @@ -158,12 +158,12 @@ extension ConnectionType { - returns: an array of `ItemType` */ - public func readAll< + public func readWithMetadataAll< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: NSCoding>() -> [(Object, Metadata?)] { - return read { $0.readAll() } + return read { $0.readWithMetadataAll() } } } @@ -176,7 +176,7 @@ extension WriteTransactionType { - parameter item: the item to store. */ - public func write< + public func writeWithMetadata< Object, Metadata where Object: Persistable, Object: NSCoding, @@ -190,14 +190,14 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ - public func write< + public func writeWithMetadata< Items, Object, Metadata where Items: SequenceType, Items.Generator.Element == (Object, Metadata?), Object: Persistable, Object: NSCoding, Metadata: NSCoding>(items: Items) -> [(Object, Metadata?)] { - return items.map(write) + return items.map(writeWithMetadata) } } @@ -208,12 +208,12 @@ extension ConnectionType { - parameter item: the item to store. */ - public func write< + public func writeWithMetadata< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: NSCoding>(item: (Object, Metadata?)) -> (Object, Metadata?) { - return write { $0.write(item) } + return write { $0.writeWithMetadata(item) } } /** @@ -221,14 +221,14 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ - public func write< + public func writeWithMetadata< Items, Object, Metadata where Items: SequenceType, Items.Generator.Element == (Object, Metadata?), Object: Persistable, Object: NSCoding, Metadata: NSCoding>(items: Items) -> [(Object, Metadata?)] { - return write { $0.write(items) } + return write { $0.writeWithMetadata(items) } } /** @@ -238,12 +238,12 @@ extension ConnectionType { - parameter queue: the dispatch_queue_t to run the completion block on. - parameter completion: a dispatch_block_t for completion. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: NSCoding>(item: (Object, Metadata?), queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Object, Metadata?) -> Void)? = .None) { - asyncWrite({ $0.write(item) }, queue: queue, completion: completion) + asyncWrite({ $0.writeWithMetadata(item) }, queue: queue, completion: completion) } /** @@ -253,14 +253,14 @@ extension ConnectionType { - parameter queue: the dispatch_queue_t to run the completion block on. - parameter completion: a dispatch_block_t for completion. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Items, Object, Metadata where Items: SequenceType, Items.Generator.Element == (Object, Metadata?), Object: Persistable, Object: NSCoding, Metadata: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Object, Metadata?)] -> Void)? = .None) { - asyncWrite({ $0.write(items) }, queue: queue, completion: completion) + asyncWrite({ $0.writeWithMetadata(items) }, queue: queue, completion: completion) } } diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithValueMetadata.swift index cc5f0a8..cd0b332 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithValueMetadata.swift @@ -20,7 +20,7 @@ extension ReadTransactionType { - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func readAtIndex< + public func readWithMetadataAtIndex< Object, Metadata where Object: Persistable, Object: NSCoding, @@ -38,7 +38,7 @@ extension ReadTransactionType { - parameter indexes: a SequenceType of YapDB.Index values - returns: an array of `ItemType` */ - public func readAtIndexes< + public func readWithMetadataAtIndexes< Indexes, Object, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, @@ -48,7 +48,7 @@ extension ReadTransactionType { Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(Object, Metadata?)] { // FIXME: using flatMap means the output length need not match the input length - return indexes.flatMap(readAtIndex) + return indexes.flatMap(readWithMetadataAtIndex) } /** @@ -57,14 +57,14 @@ extension ReadTransactionType { - parameter key: a String - returns: an optional `ItemType` */ - public func readByKey< + public func readWithMetadataByKey< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(key: String) -> (Object, Metadata?)? { - return readAtIndex(Object.indexWithKey(key)) + return readWithMetadataAtIndex(Object.indexWithKey(key)) } /** @@ -73,7 +73,7 @@ extension ReadTransactionType { - parameter keys: a SequenceType of String values - returns: an array of `ItemType` */ - public func readByKeys< + public func readWithMetadataByKeys< Keys, Object, Metadata where Keys: SequenceType, Keys.Generator.Element == String, @@ -82,7 +82,7 @@ extension ReadTransactionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(Object, Metadata?)] { - return readAtIndexes(Object.indexesWithKeys(keys)) + return readWithMetadataAtIndexes(Object.indexesWithKeys(keys)) } /** @@ -90,14 +90,14 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ - public func readAll< + public func readWithMetadataAll< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>() -> [(Object, Metadata?)] { - return readByKeys(keysInCollection(Object.collection)) + return readWithMetadataByKeys(keysInCollection(Object.collection)) } } @@ -109,14 +109,14 @@ extension ConnectionType { - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func readAtIndex< + public func readWithMetadataAtIndex< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (Object, Metadata?)? { - return read { $0.readAtIndex(index) } + return read { $0.readWithMetadataAtIndex(index) } } /** @@ -125,7 +125,7 @@ extension ConnectionType { - parameter indexes: a SequenceType of YapDB.Index values - returns: an array of `ItemType` */ - public func readAtIndexes< + public func readWithMetadataAtIndexes< Indexes, Object, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, @@ -134,7 +134,7 @@ extension ConnectionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(Object, Metadata?)] { - return read { $0.readAtIndexes(indexes) } + return read { $0.readWithMetadataAtIndexes(indexes) } } /** @@ -143,14 +143,14 @@ extension ConnectionType { - parameter key: a String - returns: an optional `ItemType` */ - public func readByKey< + public func readWithMetadataByKey< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(key: String) -> (Object, Metadata?)? { - return readAtIndex(Object.indexWithKey(key)) + return readWithMetadataAtIndex(Object.indexWithKey(key)) } /** @@ -159,7 +159,7 @@ extension ConnectionType { - parameter keys: a SequenceType of String values - returns: an array of `ItemType` */ - public func readByKeys< + public func readWithMetadataByKeys< Keys, Object, Metadata where Keys: SequenceType, Keys.Generator.Element == String, @@ -168,7 +168,7 @@ extension ConnectionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(Object, Metadata?)] { - return readAtIndexes(Object.indexesWithKeys(keys)) + return readWithMetadataAtIndexes(Object.indexesWithKeys(keys)) } /** @@ -176,14 +176,14 @@ extension ConnectionType { - returns: an array of `ItemType` */ - public func readAll< + public func readWithMetadataAll< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>() -> [(Object, Metadata?)] { - return read { $0.readAll() } + return read { $0.readWithMetadataAll() } } } @@ -196,7 +196,7 @@ extension WriteTransactionType { - parameter item: the item to store. */ - public func write< + public func writeWithMetadata< Object, Metadata where Object: Persistable, Object: NSCoding, @@ -212,7 +212,7 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ - public func write< + public func writeWithMetadata< Items, Object, Metadata where Items: SequenceType, Items.Generator.Element == (Object, Metadata?), @@ -221,7 +221,7 @@ extension WriteTransactionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(items: Items) -> [(Object, Metadata?)] { - return items.map(write) + return items.map(writeWithMetadata) } } @@ -232,14 +232,14 @@ extension ConnectionType { - parameter item: the item to store. */ - public func write< + public func writeWithMetadata< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(item: (Object, Metadata?)) -> (Object, Metadata?) { - return write { $0.write(item) } + return write { $0.writeWithMetadata(item) } } /** @@ -247,7 +247,7 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ - public func write< + public func writeWithMetadata< Items, Object, Metadata where Items: SequenceType, Items.Generator.Element == (Object, Metadata?), @@ -256,7 +256,7 @@ extension ConnectionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(items: Items) -> [(Object, Metadata?)] { - return write { $0.write(items) } + return write { $0.writeWithMetadata(items) } } /** @@ -266,14 +266,14 @@ extension ConnectionType { - parameter queue: the dispatch_queue_t to run the completion block on. - parameter completion: a dispatch_block_t for completion. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Object, Metadata where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(item: (Object, Metadata?), queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Object, Metadata?) -> Void)? = .None) { - asyncWrite({ $0.write(item) }, queue: queue, completion: completion) + asyncWrite({ $0.writeWithMetadata(item) }, queue: queue, completion: completion) } /** @@ -283,7 +283,7 @@ extension ConnectionType { - parameter queue: the dispatch_queue_t to run the completion block on. - parameter completion: a dispatch_block_t for completion. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Items, Object, Metadata where Items: SequenceType, Items.Generator.Element == (Object, Metadata?), @@ -292,7 +292,7 @@ extension ConnectionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Object, Metadata?)] -> Void)? = .None) { - asyncWrite({ $0.write(items) }, queue: queue, completion: completion) + asyncWrite({ $0.writeWithMetadata(items) }, queue: queue, completion: completion) } } diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthObjectMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthObjectMetadata.swift index 1344b75..1b14983 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthObjectMetadata.swift @@ -20,7 +20,7 @@ extension ReadTransactionType { - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func readAtIndex< + public func readWithMetadataAtIndex< Value, Metadata where Value: Persistable, Value: ValueCoding, @@ -38,7 +38,7 @@ extension ReadTransactionType { - parameter indexes: a SequenceType of YapDB.Index values - returns: an array of `ItemType` */ - public func readAtIndexes< + public func readWithMetadataAtIndexes< Indexes, Value, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, @@ -48,7 +48,7 @@ extension ReadTransactionType { Value.Coder.ValueType == Value, Metadata: NSCoding>(indexes: Indexes) -> [(Value, Metadata?)] { // FIXME: using flatMap means the output length need not match the input length - return indexes.flatMap(readAtIndex) + return indexes.flatMap(readWithMetadataAtIndex) } /** @@ -57,14 +57,14 @@ extension ReadTransactionType { - parameter key: a String - returns: an optional `ItemType` */ - public func readByKey< + public func readWithMetadataByKey< Value, Metadata where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: NSCoding>(key: String) -> (Value, Metadata?)? { - return readAtIndex(Value.indexWithKey(key)) + return readWithMetadataAtIndex(Value.indexWithKey(key)) } /** @@ -73,7 +73,7 @@ extension ReadTransactionType { - parameter keys: a SequenceType of String values - returns: an array of `ItemType` */ - public func readByKeys< + public func readWithMetadataByKeys< Keys, Value, Metadata where Keys: SequenceType, Keys.Generator.Element == String, @@ -82,7 +82,7 @@ extension ReadTransactionType { Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: NSCoding>(keys: Keys) -> [(Value, Metadata?)] { - return readAtIndexes(Value.indexesWithKeys(keys)) + return readWithMetadataAtIndexes(Value.indexesWithKeys(keys)) } /** @@ -90,14 +90,14 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ - public func readAll< + public func readWithMetadataAll< Value, Metadata where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: NSCoding>() -> [(Value, Metadata?)] { - return readByKeys(keysInCollection(Value.collection)) + return readWithMetadataByKeys(keysInCollection(Value.collection)) } } @@ -109,14 +109,14 @@ extension ConnectionType { - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func readAtIndex< + public func readWithMetadataAtIndex< Value, Metadata where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: NSCoding>(index: YapDB.Index) -> (Value, Metadata?)? { - return read { $0.readAtIndex(index) } + return read { $0.readWithMetadataAtIndex(index) } } /** @@ -125,7 +125,7 @@ extension ConnectionType { - parameter indexes: a SequenceType of YapDB.Index values - returns: an array of `ItemType` */ - public func readAtIndexes< + public func readWithMetadataAtIndexes< Indexes, Value, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, @@ -134,7 +134,7 @@ extension ConnectionType { Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: NSCoding>(indexes: Indexes) -> [(Value, Metadata?)] { - return read { $0.readAtIndexes(indexes) } + return read { $0.readWithMetadataAtIndexes(indexes) } } /** @@ -143,14 +143,14 @@ extension ConnectionType { - parameter key: a String - returns: an optional `ItemType` */ - public func readByKey< + public func readWithMetadataByKey< Value, Metadata where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: NSCoding>(key: String) -> (Value, Metadata?)? { - return readAtIndex(Value.indexWithKey(key)) + return readWithMetadataAtIndex(Value.indexWithKey(key)) } /** @@ -159,7 +159,7 @@ extension ConnectionType { - parameter keys: a SequenceType of String values - returns: an array of `ItemType` */ - public func readByKeys< + public func readWithMetadataByKeys< Keys, Value, Metadata where Keys: SequenceType, Keys.Generator.Element == String, @@ -168,7 +168,7 @@ extension ConnectionType { Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: NSCoding>(keys: Keys) -> [(Value, Metadata?)] { - return readAtIndexes(Value.indexesWithKeys(keys)) + return readWithMetadataAtIndexes(Value.indexesWithKeys(keys)) } /** @@ -176,14 +176,14 @@ extension ConnectionType { - returns: an array of `ItemType` */ - public func readAll< + public func readWithMetadataAll< Value, Metadata where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: NSCoding>() -> [(Value, Metadata?)] { - return read { $0.readAll() } + return read { $0.readWithMetadataAll() } } } @@ -196,7 +196,7 @@ extension WriteTransactionType { - parameter item: the item to store. */ - public func write< + public func writeWithMetadata< Value, Metadata where Value: Persistable, Value: ValueCoding, @@ -212,7 +212,7 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ - public func write< + public func writeWithMetadata< Items, Value, Metadata where Items: SequenceType, Items.Generator.Element == (Value, Metadata?), @@ -221,7 +221,7 @@ extension WriteTransactionType { Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: NSCoding>(items: Items) -> [(Value, Metadata?)] { - return items.map(write) + return items.map(writeWithMetadata) } } @@ -232,14 +232,14 @@ extension ConnectionType { - parameter item: the item to store. */ - public func write< + public func writeWithMetadata< Value, Metadata where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: NSCoding>(item: (Value, Metadata?)) -> (Value, Metadata?) { - return write { $0.write(item) } + return write { $0.writeWithMetadata(item) } } /** @@ -247,7 +247,7 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ - public func write< + public func writeWithMetadata< Items, Value, Metadata where Items: SequenceType, Items.Generator.Element == (Value, Metadata?), @@ -256,7 +256,7 @@ extension ConnectionType { Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: NSCoding>(items: Items) -> [(Value, Metadata?)] { - return write { $0.write(items) } + return write { $0.writeWithMetadata(items) } } /** @@ -266,14 +266,14 @@ extension ConnectionType { - parameter queue: the dispatch_queue_t to run the completion block on. - parameter completion: a dispatch_block_t for completion. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Value, Metadata where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: NSCoding>(item: (Value, Metadata?), queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Value, Metadata?) -> Void)? = .None) { - asyncWrite({ $0.write(item) }, queue: queue, completion: completion) + asyncWrite({ $0.writeWithMetadata(item) }, queue: queue, completion: completion) } /** @@ -283,7 +283,7 @@ extension ConnectionType { - parameter queue: the dispatch_queue_t to run the completion block on. - parameter completion: a dispatch_block_t for completion. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Items, Value, Metadata where Items: SequenceType, Items.Generator.Element == (Value, Metadata?), @@ -292,7 +292,7 @@ extension ConnectionType { Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Value, Metadata?)] -> Void)? = .None) { - asyncWrite({ $0.write(items) }, queue: queue, completion: completion) + asyncWrite({ $0.writeWithMetadata(items) }, queue: queue, completion: completion) } } diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthValueMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthValueMetadata.swift index 217205d..ea95096 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthValueMetadata.swift @@ -20,7 +20,7 @@ extension ReadTransactionType { - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func readAtIndex< + public func readWithMetadataAtIndex< Value, Metadata where Value: Persistable, Value: ValueCoding, @@ -40,7 +40,7 @@ extension ReadTransactionType { - parameter indexes: a SequenceType of YapDB.Index values - returns: an array of `ItemType` */ - public func readAtIndexes< + public func readWithMetadataAtIndexes< Indexes, Value, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, @@ -52,7 +52,7 @@ extension ReadTransactionType { Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(Value, Metadata?)] { // FIXME: using flatMap means the output length need not match the input length - return indexes.flatMap(readAtIndex) + return indexes.flatMap(readWithMetadataAtIndex) } /** @@ -61,7 +61,7 @@ extension ReadTransactionType { - parameter key: a String - returns: an optional `ItemType` */ - public func readByKey< + public func readWithMetadataByKey< Value, Metadata where Value: Persistable, Value: ValueCoding, @@ -70,7 +70,7 @@ extension ReadTransactionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(key: String) -> (Value, Metadata?)? { - return readAtIndex(Value.indexWithKey(key)) + return readWithMetadataAtIndex(Value.indexWithKey(key)) } /** @@ -79,7 +79,7 @@ extension ReadTransactionType { - parameter keys: a SequenceType of String values - returns: an array of `ItemType` */ - public func readByKeys< + public func readWithMetadataByKeys< Keys, Value, Metadata where Keys: SequenceType, Keys.Generator.Element == String, @@ -90,7 +90,7 @@ extension ReadTransactionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(Value, Metadata?)] { - return readAtIndexes(Value.indexesWithKeys(keys)) + return readWithMetadataAtIndexes(Value.indexesWithKeys(keys)) } /** @@ -98,7 +98,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ - public func readAll< + public func readWithMetadataAll< Value, Metadata where Value: Persistable, Value: ValueCoding, @@ -107,7 +107,7 @@ extension ReadTransactionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>() -> [(Value, Metadata?)] { - return readByKeys(keysInCollection(Value.collection)) + return readWithMetadataByKeys(keysInCollection(Value.collection)) } } @@ -119,7 +119,7 @@ extension ConnectionType { - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func readAtIndex< + public func readWithMetadataAtIndex< Value, Metadata where Value: Persistable, Value: ValueCoding, @@ -128,7 +128,7 @@ extension ConnectionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (Value, Metadata?)? { - return read { $0.readAtIndex(index) } + return read { $0.readWithMetadataAtIndex(index) } } /** @@ -137,7 +137,7 @@ extension ConnectionType { - parameter indexes: a SequenceType of YapDB.Index values - returns: an array of `ItemType` */ - public func readAtIndexes< + public func readWithMetadataAtIndexes< Indexes, Value, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, @@ -148,7 +148,7 @@ extension ConnectionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(Value, Metadata?)] { - return read { $0.readAtIndexes(indexes) } + return read { $0.readWithMetadataAtIndexes(indexes) } } /** @@ -157,7 +157,7 @@ extension ConnectionType { - parameter key: a String - returns: an optional `ItemType` */ - public func readByKey< + public func readWithMetadataByKey< Value, Metadata where Value: Persistable, Value: ValueCoding, @@ -166,7 +166,7 @@ extension ConnectionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(key: String) -> (Value, Metadata?)? { - return readAtIndex(Value.indexWithKey(key)) + return readWithMetadataAtIndex(Value.indexWithKey(key)) } /** @@ -175,7 +175,7 @@ extension ConnectionType { - parameter keys: a SequenceType of String values - returns: an array of `ItemType` */ - public func readByKeys< + public func readWithMetadataByKeys< Keys, Value, Metadata where Keys: SequenceType, Keys.Generator.Element == String, @@ -186,7 +186,7 @@ extension ConnectionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(Value, Metadata?)] { - return readAtIndexes(Value.indexesWithKeys(keys)) + return readWithMetadataAtIndexes(Value.indexesWithKeys(keys)) } /** @@ -194,7 +194,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ - public func readAll< + public func readWithMetadataAll< Value, Metadata where Value: Persistable, Value: ValueCoding, @@ -203,7 +203,7 @@ extension ConnectionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>() -> [(Value, Metadata?)] { - return read { $0.readAll() } + return read { $0.readWithMetadataAll() } } } @@ -216,7 +216,7 @@ extension WriteTransactionType { - parameter item: the item to store. */ - public func write< + public func writeWithMetadata< Value, Metadata where Value: Persistable, Value: ValueCoding, @@ -234,7 +234,7 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ - public func write< + public func writeWithMetadata< Items, Value, Metadata where Items: SequenceType, Items.Generator.Element == (Value, Metadata?), @@ -245,7 +245,7 @@ extension WriteTransactionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(items: Items) -> [(Value, Metadata?)] { - return items.map(write) + return items.map(writeWithMetadata) } } @@ -256,7 +256,7 @@ extension ConnectionType { - parameter item: the item to store. */ - public func write< + public func writeWithMetadata< Value, Metadata where Value: Persistable, Value: ValueCoding, @@ -265,7 +265,7 @@ extension ConnectionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(item: (Value, Metadata?)) -> (Value, Metadata?) { - return write { $0.write(item) } + return write { $0.writeWithMetadata(item) } } /** @@ -273,7 +273,7 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ - public func write< + public func writeWithMetadata< Items, Value, Metadata where Items: SequenceType, Items.Generator.Element == (Value, Metadata?), @@ -284,7 +284,7 @@ extension ConnectionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(items: Items) -> [(Value, Metadata?)] { - return write { $0.write(items) } + return write { $0.writeWithMetadata(items) } } /** @@ -294,7 +294,7 @@ extension ConnectionType { - parameter queue: the dispatch_queue_t to run the completion block on. - parameter completion: a dispatch_block_t for completion. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Value, Metadata where Value: Persistable, Value: ValueCoding, @@ -303,7 +303,7 @@ extension ConnectionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(item: (Value, Metadata?), queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Value, Metadata?) -> Void)? = .None) { - asyncWrite({ $0.write(item) }, queue: queue, completion: completion) + asyncWrite({ $0.writeWithMetadata(item) }, queue: queue, completion: completion) } /** @@ -313,7 +313,7 @@ extension ConnectionType { - parameter queue: the dispatch_queue_t to run the completion block on. - parameter completion: a dispatch_block_t for completion. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Items, Value, Metadata where Items: SequenceType, Items.Generator.Element == (Value, Metadata?), @@ -324,7 +324,7 @@ extension ConnectionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Value, Metadata?)] -> Void)? = .None) { - asyncWrite({ $0.write(items) }, queue: queue, completion: completion) + asyncWrite({ $0.writeWithMetadata(items) }, queue: queue, completion: completion) } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift index a6c7180..95c0444 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift @@ -21,11 +21,11 @@ extension Persistable where - parameter transaction: a YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write< + public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata? = nil) -> (Self, Metadata?) { - return transaction.write((self, metadata)) + return transaction.writeWithMetadata((self, metadata)) } /** @@ -34,11 +34,11 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: the receiver. */ - public func write< + public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil) -> (Self, Metadata?) { - return connection.write((self, metadata)) + return connection.writeWithMetadata((self, metadata)) } /** @@ -47,11 +47,11 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { - return connection.asyncWrite((self, metadata), queue: queue, completion: completion) + return connection.asyncWriteWithMetadata((self, metadata), queue: queue, completion: completion) } /** @@ -60,11 +60,11 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation< + public func writeWithMetadataOperation< Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil) -> NSOperation { - return NSBlockOperation { connection.write((self, metadata)) } + return NSBlockOperation { connection.writeWithMetadata((self, metadata)) } } } @@ -78,12 +78,12 @@ extension SequenceType where - parameter transaction: a WriteTransactionType e.g. YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write< + public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) - return transaction.write(items) + return transaction.writeWithMetadata(items) } /** @@ -92,12 +92,12 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: the receiver. */ - public func write< + public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) - return connection.write(items) + return connection.writeWithMetadata(items) } /** @@ -106,12 +106,12 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { let items = zipToWrite(self, metadata) - return connection.asyncWrite(items, queue: queue, completion: completion) + return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } /** @@ -120,12 +120,12 @@ extension SequenceType where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation< + public func writeWithMetadataOperation< Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { let items = zipToWrite(self, metadata) - return NSBlockOperation { connection.write(items) } + return NSBlockOperation { connection.writeWithMetadata(items) } } } @@ -136,42 +136,42 @@ extension Readable where ItemType: NSCoding, ItemType: Persistable { - func inTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { - return transaction.readAtIndex(index) + func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { + return transaction.readWithMetadataAtIndex(index) } - func inTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { - return { self.inTransaction(transaction, atIndex: $0) } + func withMetadataInTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { + return { self.withMetadataInTransaction(transaction, atIndex: $0) } } - func atIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { - return { self.inTransaction($0, atIndex: index) } + func withMetadataAtIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { + return { self.withMetadataInTransaction($0, atIndex: index) } } - func atIndexesInTransaction< + func withMetadataAtIndexesInTransaction< Indexes, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, Metadata: NSCoding>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { - return { indexes.flatMap(self.inTransactionAtIndex($0)) } + return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } } - func inTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { - return inTransaction(transaction, atIndex: ItemType.indexWithKey(key)) + func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { + return withMetadataInTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func inTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { - return { self.inTransaction(transaction, byKey: $0) } + func withMetadataInTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { + return { self.withMetadataInTransaction(transaction, byKey: $0) } } - func byKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { - return { self.inTransaction($0, byKey: key) } + func withMetadataByKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { + return { self.withMetadataInTransaction($0, byKey: key) } } - func byKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + func withMetadataByKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(self.inTransactionByKey(transaction)) + return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) } } @@ -181,8 +181,8 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func atIndex(index: YapDB.Index) -> (ItemType, Metadata?)? { - return sync(atIndexInTransaction(index)) + public func withMetadataAtIndex(index: YapDB.Index) -> (ItemType, Metadata?)? { + return sync(withMetadataAtIndexInTransaction(index)) } /** @@ -191,12 +191,12 @@ extension Readable where - parameter indexes: a SequenceType of YapDB.Index values - returns: an array of `ItemType` */ - public func atIndexes< + public func withMetadataAtIndexes< Indexes, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, Metadata: NSCoding>(indexes: Indexes) -> [(ItemType, Metadata?)] { - return sync(atIndexesInTransaction(indexes)) + return sync(withMetadataAtIndexesInTransaction(indexes)) } /** @@ -205,8 +205,8 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func byKey(key: String) -> (ItemType, Metadata?)? { - return sync(byKeyInTransaction(key)) + public func withMetadataByKey(key: String) -> (ItemType, Metadata?)? { + return sync(withMetadataByKeyInTransaction(key)) } /** @@ -215,12 +215,12 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: an array of `ItemType` */ - public func byKeys< + public func withMetadataByKeys< Keys, Metadata where Keys: SequenceType, Keys.Generator.Element == String, Metadata: NSCoding>(keys: Keys) -> [(ItemType, Metadata?)] { - return sync(byKeysInTransaction(Array(keys))) + return sync(withMetadataByKeysInTransaction(Array(keys))) } /** @@ -228,8 +228,8 @@ extension Readable where - returns: an array of `ItemType` */ - public func all() -> [(ItemType, Metadata?)] { - return sync(byKeysInTransaction()) + public func withMetadataAll() -> [(ItemType, Metadata?)] { + return sync(withMetadataByKeysInTransaction()) } /** @@ -238,8 +238,8 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func filterExisting(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { - let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = byKeysInTransaction(keys) + public func withMetadataFilterExisting(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { + let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = withMetadataByKeysInTransaction(keys) return sync { transaction -> ([(ItemType, Metadata?)], [String]) in let existing = existingInTransaction(transaction) let existingKeys = existing.map {keyForPersistable($0.0)} diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift index 7642ba8..7cff7de 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift @@ -22,13 +22,13 @@ extension Persistable where - parameter transaction: a YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write< + public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata? = nil) -> (Self, Metadata?) { - return transaction.write((self, metadata)) + return transaction.writeWithMetadata((self, metadata)) } /** @@ -37,13 +37,13 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: the receiver. */ - public func write< + public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil) -> (Self, Metadata?) { - return connection.write((self, metadata)) + return connection.writeWithMetadata((self, metadata)) } /** @@ -52,13 +52,13 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { - return connection.asyncWrite((self, metadata), queue: queue, completion: completion) + return connection.asyncWriteWithMetadata((self, metadata), queue: queue, completion: completion) } /** @@ -67,13 +67,13 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation< + public func writeWithMetadataOperation< Connection, Metadata where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil) -> NSOperation { - return NSBlockOperation { connection.write((self, metadata)) } + return NSBlockOperation { connection.writeWithMetadata((self, metadata)) } } } @@ -87,14 +87,14 @@ extension SequenceType where - parameter transaction: a WriteTransactionType e.g. YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write< + public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) - return transaction.write(items) + return transaction.writeWithMetadata(items) } /** @@ -103,14 +103,14 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: the receiver. */ - public func write< + public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) - return connection.write(items) + return connection.writeWithMetadata(items) } /** @@ -119,14 +119,14 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { let items = zipToWrite(self, metadata) - return connection.asyncWrite(items, queue: queue, completion: completion) + return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } /** @@ -135,14 +135,14 @@ extension SequenceType where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation< + public func writeWithMetadataOperation< Connection, Metadata where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { let items = zipToWrite(self, metadata) - return NSBlockOperation { connection.write(items) } + return NSBlockOperation { connection.writeWithMetadata(items) } } } @@ -152,72 +152,72 @@ extension Readable where ItemType: NSCoding, ItemType: Persistable { - func inTransaction< + func withMetadataInTransaction< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { - return transaction.readAtIndex(index) + return transaction.readWithMetadataAtIndex(index) } - func inTransactionAtIndex< + func withMetadataInTransactionAtIndex< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { - return { self.inTransaction(transaction, atIndex: $0) } + return { self.withMetadataInTransaction(transaction, atIndex: $0) } } - func atIndexInTransaction< + func withMetadataAtIndexInTransaction< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { - return { self.inTransaction($0, atIndex: index) } + return { self.withMetadataInTransaction($0, atIndex: index) } } - func atIndexesInTransaction< + func withMetadataAtIndexesInTransaction< Indexes, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { - return { indexes.flatMap(self.inTransactionAtIndex($0)) } + return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } } - func inTransaction< + func withMetadataInTransaction< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { - return inTransaction(transaction, atIndex: ItemType.indexWithKey(key)) + return withMetadataInTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func inTransactionByKey< + func withMetadataInTransactionByKey< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { - return { self.inTransaction(transaction, byKey: $0) } + return { self.withMetadataInTransaction(transaction, byKey: $0) } } - func byKeyInTransaction< + func withMetadataByKeyInTransaction< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { - return { self.inTransaction($0, byKey: key) } + return { self.withMetadataInTransaction($0, byKey: key) } } - func byKeysInTransaction< + func withMetadataByKeysInTransaction< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(self.inTransactionByKey(transaction)) + return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) } } @@ -227,12 +227,12 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func atIndex< + public func withMetadataAtIndex< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (ItemType, Metadata?)? { - return sync(atIndexInTransaction(index)) + return sync(withMetadataAtIndexInTransaction(index)) } /** @@ -241,14 +241,14 @@ extension Readable where - parameter indexes: a SequenceType of YapDB.Index values - returns: an array of `ItemType` */ - public func atIndexes< + public func withMetadataAtIndexes< Indexes, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(ItemType, Metadata?)] { - return sync(atIndexesInTransaction(indexes)) + return sync(withMetadataAtIndexesInTransaction(indexes)) } /** @@ -257,12 +257,12 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func byKey< + public func withMetadataByKey< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(key: String) -> (ItemType, Metadata?)? { - return sync(byKeyInTransaction(key)) + return sync(withMetadataByKeyInTransaction(key)) } /** @@ -271,14 +271,14 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: an array of `ItemType` */ - public func byKeys< + public func withMetadataByKeys< Keys, Metadata where Keys: SequenceType, Keys.Generator.Element == String, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(ItemType, Metadata?)] { - return sync(byKeysInTransaction(Array(keys))) + return sync(withMetadataByKeysInTransaction(Array(keys))) } /** @@ -286,12 +286,12 @@ extension Readable where - returns: an array of `ItemType` */ - public func all< + public func withMetadataAll< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>() -> [(ItemType, Metadata?)] { - return sync(byKeysInTransaction()) + return sync(withMetadataByKeysInTransaction()) } /** @@ -300,12 +300,12 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func filterExisting< + public func withMetadataFilterExisting< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { - let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = byKeysInTransaction(keys) + let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = withMetadataByKeysInTransaction(keys) return sync { transaction -> ([(ItemType, Metadata?)], [String]) in let existing = existingInTransaction(transaction) let existingKeys = existing.map {keyForPersistable($0.0)} diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift index 9d2703c..0533da6 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift @@ -24,11 +24,11 @@ extension Persistable where - parameter transaction: a YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write< + public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata? = nil) -> (Self, Metadata?) { - return transaction.write((self, metadata)) + return transaction.writeWithMetadata((self, metadata)) } /** @@ -37,11 +37,11 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: the receiver. */ - public func write< + public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil) -> (Self, Metadata?) { - return connection.write((self, metadata)) + return connection.writeWithMetadata((self, metadata)) } /** @@ -50,11 +50,11 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { - return connection.asyncWrite((self, metadata), queue: queue, completion: completion) + return connection.asyncWriteWithMetadata((self, metadata), queue: queue, completion: completion) } /** @@ -63,11 +63,11 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation< + public func writeWithMetadataOperation< Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil) -> NSOperation { - return NSBlockOperation { connection.write((self, metadata)) } + return NSBlockOperation { connection.writeWithMetadata((self, metadata)) } } } @@ -83,12 +83,12 @@ extension SequenceType where - parameter transaction: a WriteTransactionType e.g. YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write< + public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) - return transaction.write(items) + return transaction.writeWithMetadata(items) } /** @@ -97,12 +97,12 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: the receiver. */ - public func write< + public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) - return connection.write(items) + return connection.writeWithMetadata(items) } /** @@ -111,12 +111,12 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { let items = zipToWrite(self, metadata) - return connection.asyncWrite(items, queue: queue, completion: completion) + return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } /** @@ -125,12 +125,12 @@ extension SequenceType where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation< + public func writeWithMetadataOperation< Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { let items = zipToWrite(self, metadata) - return NSBlockOperation { connection.write(items) } + return NSBlockOperation { connection.writeWithMetadata(items) } } } @@ -143,42 +143,42 @@ extension Readable where ItemType.Coder: NSCoding, ItemType.Coder.ValueType == ItemType { - func inTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { - return transaction.readAtIndex(index) + func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { + return transaction.readWithMetadataAtIndex(index) } - func inTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { - return { self.inTransaction(transaction, atIndex: $0) } + func withMetadataInTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { + return { self.withMetadataInTransaction(transaction, atIndex: $0) } } - func atIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { - return { self.inTransaction($0, atIndex: index) } + func withMetadataAtIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { + return { self.withMetadataInTransaction($0, atIndex: index) } } - func atIndexesInTransaction< + func withMetadataAtIndexesInTransaction< Indexes, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, Metadata: NSCoding>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { - return { indexes.flatMap(self.inTransactionAtIndex($0)) } + return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } } - func inTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { - return inTransaction(transaction, atIndex: ItemType.indexWithKey(key)) + func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { + return withMetadataInTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func inTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { - return { self.inTransaction(transaction, byKey: $0) } + func withMetadataInTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { + return { self.withMetadataInTransaction(transaction, byKey: $0) } } - func byKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { - return { self.inTransaction($0, byKey: key) } + func withMetadataByKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { + return { self.withMetadataInTransaction($0, byKey: key) } } - func byKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + func withMetadataByKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(self.inTransactionByKey(transaction)) + return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) } } @@ -188,8 +188,8 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func atIndex(index: YapDB.Index) -> (ItemType, Metadata?)? { - return sync(atIndexInTransaction(index)) + public func withMetadataAtIndex(index: YapDB.Index) -> (ItemType, Metadata?)? { + return sync(withMetadataAtIndexInTransaction(index)) } /** @@ -198,12 +198,12 @@ extension Readable where - parameter indexes: a SequenceType of YapDB.Index values - returns: an array of `ItemType` */ - public func atIndexes< + public func withMetadataAtIndexes< Indexes, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, Metadata: NSCoding>(indexes: Indexes) -> [(ItemType, Metadata?)] { - return sync(atIndexesInTransaction(indexes)) + return sync(withMetadataAtIndexesInTransaction(indexes)) } /** @@ -212,8 +212,8 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func byKey(key: String) -> (ItemType, Metadata?)? { - return sync(byKeyInTransaction(key)) + public func withMetadataByKey(key: String) -> (ItemType, Metadata?)? { + return sync(withMetadataByKeyInTransaction(key)) } /** @@ -222,12 +222,12 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: an array of `ItemType` */ - public func byKeys< + public func withMetadataByKeys< Keys, Metadata where Keys: SequenceType, Keys.Generator.Element == String, Metadata: NSCoding>(keys: Keys) -> [(ItemType, Metadata?)] { - return sync(byKeysInTransaction(Array(keys))) + return sync(withMetadataByKeysInTransaction(Array(keys))) } /** @@ -235,8 +235,8 @@ extension Readable where - returns: an array of `ItemType` */ - public func all() -> [(ItemType, Metadata?)] { - return sync(byKeysInTransaction()) + public func withMetadataAll() -> [(ItemType, Metadata?)] { + return sync(withMetadataByKeysInTransaction()) } /** @@ -245,8 +245,8 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func filterExisting(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { - let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = byKeysInTransaction(keys) + public func withMetadataFilterExisting(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { + let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = withMetadataByKeysInTransaction(keys) return sync { transaction -> ([(ItemType, Metadata?)], [String]) in let existing = existingInTransaction(transaction) let existingKeys = existing.map {keyForPersistable($0.0)} diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift index db778c1..a651ef5 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift @@ -24,13 +24,13 @@ extension Persistable where - parameter transaction: a YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write< + public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata? = nil) -> (Self, Metadata?) { - return transaction.write((self, metadata)) + return transaction.writeWithMetadata((self, metadata)) } /** @@ -39,13 +39,13 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: the receiver. */ - public func write< + public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil) -> (Self, Metadata?) { - return connection.write((self, metadata)) + return connection.writeWithMetadata((self, metadata)) } /** @@ -54,13 +54,13 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { - return connection.asyncWrite((self, metadata), queue: queue, completion: completion) + return connection.asyncWriteWithMetadata((self, metadata), queue: queue, completion: completion) } /** @@ -69,13 +69,13 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation< + public func writeWithMetadataOperation< Connection, Metadata where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil) -> NSOperation { - return NSBlockOperation { connection.write((self, metadata)) } + return NSBlockOperation { connection.writeWithMetadata((self, metadata)) } } } @@ -91,14 +91,14 @@ extension SequenceType where - parameter transaction: a WriteTransactionType e.g. YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write< + public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) - return transaction.write(items) + return transaction.writeWithMetadata(items) } /** @@ -107,14 +107,14 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: the receiver. */ - public func write< + public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) - return connection.write(items) + return connection.writeWithMetadata(items) } /** @@ -123,14 +123,14 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite< + public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { let items = zipToWrite(self, metadata) - return connection.asyncWrite(items, queue: queue, completion: completion) + return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } /** @@ -139,14 +139,14 @@ extension SequenceType where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation< + public func writeWithMetadataOperation< Connection, Metadata where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { let items = zipToWrite(self, metadata) - return NSBlockOperation { connection.write(items) } + return NSBlockOperation { connection.writeWithMetadata(items) } } } @@ -158,72 +158,72 @@ extension Readable where ItemType.Coder: NSCoding, ItemType.Coder.ValueType == ItemType { - func inTransaction< + func withMetadataInTransaction< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { - return transaction.readAtIndex(index) + return transaction.readWithMetadataAtIndex(index) } - func inTransactionAtIndex< + func withMetadataInTransactionAtIndex< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { - return { self.inTransaction(transaction, atIndex: $0) } + return { self.withMetadataInTransaction(transaction, atIndex: $0) } } - func atIndexInTransaction< + func withMetadataAtIndexInTransaction< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { - return { self.inTransaction($0, atIndex: index) } + return { self.withMetadataInTransaction($0, atIndex: index) } } - func atIndexesInTransaction< + func withMetadataAtIndexesInTransaction< Indexes, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { - return { indexes.flatMap(self.inTransactionAtIndex($0)) } + return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } } - func inTransaction< + func withMetadataInTransaction< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { - return inTransaction(transaction, atIndex: ItemType.indexWithKey(key)) + return withMetadataInTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func inTransactionByKey< + func withMetadataInTransactionByKey< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { - return { self.inTransaction(transaction, byKey: $0) } + return { self.withMetadataInTransaction(transaction, byKey: $0) } } - func byKeyInTransaction< + func withMetadataByKeyInTransaction< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { - return { self.inTransaction($0, byKey: key) } + return { self.withMetadataInTransaction($0, byKey: key) } } - func byKeysInTransaction< + func withMetadataByKeysInTransaction< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(self.inTransactionByKey(transaction)) + return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) } } @@ -233,12 +233,12 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func atIndex< + public func withMetadataAtIndex< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (ItemType, Metadata?)? { - return sync(atIndexInTransaction(index)) + return sync(withMetadataAtIndexInTransaction(index)) } /** @@ -247,14 +247,14 @@ extension Readable where - parameter indexes: a SequenceType of YapDB.Index values - returns: an array of `ItemType` */ - public func atIndexes< + public func withMetadataAtIndexes< Indexes, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(ItemType, Metadata?)] { - return sync(atIndexesInTransaction(indexes)) + return sync(withMetadataAtIndexesInTransaction(indexes)) } /** @@ -263,12 +263,12 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func byKey< + public func withMetadataByKey< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(key: String) -> (ItemType, Metadata?)? { - return sync(byKeyInTransaction(key)) + return sync(withMetadataByKeyInTransaction(key)) } /** @@ -277,14 +277,14 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: an array of `ItemType` */ - public func byKeys< + public func withMetadataByKeys< Keys, Metadata where Keys: SequenceType, Keys.Generator.Element == String, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(ItemType, Metadata?)] { - return sync(byKeysInTransaction(Array(keys))) + return sync(withMetadataByKeysInTransaction(Array(keys))) } /** @@ -292,12 +292,12 @@ extension Readable where - returns: an array of `ItemType` */ - public func all< + public func withMetadataAll< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>() -> [(ItemType, Metadata?)] { - return sync(byKeysInTransaction()) + return sync(withMetadataByKeysInTransaction()) } /** @@ -306,12 +306,12 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func filterExisting< + public func withMetadataFilterExisting< Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { - let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = byKeysInTransaction(keys) + let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = withMetadataByKeysInTransaction(keys) return sync { transaction -> ([(ItemType, Metadata?)], [String]) in let existing = existingInTransaction(transaction) let existingKeys = existing.map {keyForPersistable($0.0)} From b01270936bd6b0d8a3aa2adca774d680437278e0 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Sat, 10 Sep 2016 13:48:17 -0700 Subject: [PATCH 11/54] remove default values for metadata arguments --- .../Persistable_ObjectWithObjectMetadata.swift | 16 ++++++++-------- .../Persistable_ObjectWithValueMetadata.swift | 16 ++++++++-------- .../Persistable_ValueWithObjectMetadata.swift | 16 ++++++++-------- .../Persistable_ValueWithValueMetadata.swift | 16 ++++++++-------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift index 95c0444..0d86004 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift @@ -24,7 +24,7 @@ extension Persistable where public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata? = nil) -> (Self, Metadata?) { + Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { return transaction.writeWithMetadata((self, metadata)) } @@ -37,7 +37,7 @@ extension Persistable where public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil) -> (Self, Metadata?) { + Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { return connection.writeWithMetadata((self, metadata)) } @@ -50,7 +50,7 @@ extension Persistable where public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { + Metadata: NSCoding>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { return connection.asyncWriteWithMetadata((self, metadata), queue: queue, completion: completion) } @@ -63,7 +63,7 @@ extension Persistable where public func writeWithMetadataOperation< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil) -> NSOperation { + Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> NSOperation { return NSBlockOperation { connection.writeWithMetadata((self, metadata)) } } } @@ -81,7 +81,7 @@ extension SequenceType where public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { + Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) return transaction.writeWithMetadata(items) } @@ -95,7 +95,7 @@ extension SequenceType where public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) return connection.writeWithMetadata(items) } @@ -109,7 +109,7 @@ extension SequenceType where public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { let items = zipToWrite(self, metadata) return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } @@ -123,7 +123,7 @@ extension SequenceType where public func writeWithMetadataOperation< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> NSOperation { let items = zipToWrite(self, metadata) return NSBlockOperation { connection.writeWithMetadata(items) } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift index 7cff7de..06a9570 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift @@ -27,7 +27,7 @@ extension Persistable where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata? = nil) -> (Self, Metadata?) { + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { return transaction.writeWithMetadata((self, metadata)) } @@ -42,7 +42,7 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil) -> (Self, Metadata?) { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { return connection.writeWithMetadata((self, metadata)) } @@ -57,7 +57,7 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { return connection.asyncWriteWithMetadata((self, metadata), queue: queue, completion: completion) } @@ -72,7 +72,7 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil) -> NSOperation { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> NSOperation { return NSBlockOperation { connection.writeWithMetadata((self, metadata)) } } } @@ -92,7 +92,7 @@ extension SequenceType where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) return transaction.writeWithMetadata(items) } @@ -108,7 +108,7 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) return connection.writeWithMetadata(items) } @@ -124,7 +124,7 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { let items = zipToWrite(self, metadata) return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } @@ -140,7 +140,7 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> NSOperation { let items = zipToWrite(self, metadata) return NSBlockOperation { connection.writeWithMetadata(items) } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift index 0533da6..2a200dd 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift @@ -27,7 +27,7 @@ extension Persistable where public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata? = nil) -> (Self, Metadata?) { + Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { return transaction.writeWithMetadata((self, metadata)) } @@ -40,7 +40,7 @@ extension Persistable where public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil) -> (Self, Metadata?) { + Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { return connection.writeWithMetadata((self, metadata)) } @@ -53,7 +53,7 @@ extension Persistable where public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { + Metadata: NSCoding>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { return connection.asyncWriteWithMetadata((self, metadata), queue: queue, completion: completion) } @@ -66,7 +66,7 @@ extension Persistable where public func writeWithMetadataOperation< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata? = nil) -> NSOperation { + Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> NSOperation { return NSBlockOperation { connection.writeWithMetadata((self, metadata)) } } } @@ -86,7 +86,7 @@ extension SequenceType where public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { + Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) return transaction.writeWithMetadata(items) } @@ -100,7 +100,7 @@ extension SequenceType where public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) return connection.writeWithMetadata(items) } @@ -114,7 +114,7 @@ extension SequenceType where public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { let items = zipToWrite(self, metadata) return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } @@ -128,7 +128,7 @@ extension SequenceType where public func writeWithMetadataOperation< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> NSOperation { let items = zipToWrite(self, metadata) return NSBlockOperation { connection.writeWithMetadata(items) } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift index a651ef5..5dea161 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift @@ -29,7 +29,7 @@ extension Persistable where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata? = nil) -> (Self, Metadata?) { + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { return transaction.writeWithMetadata((self, metadata)) } @@ -44,7 +44,7 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil) -> (Self, Metadata?) { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { return connection.writeWithMetadata((self, metadata)) } @@ -59,7 +59,7 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { return connection.asyncWriteWithMetadata((self, metadata), queue: queue, completion: completion) } @@ -74,7 +74,7 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata? = nil) -> NSOperation { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> NSOperation { return NSBlockOperation { connection.writeWithMetadata((self, metadata)) } } } @@ -96,7 +96,7 @@ extension SequenceType where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) return transaction.writeWithMetadata(items) } @@ -112,7 +112,7 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> [(Generator.Element, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { let items = zipToWrite(self, metadata) return connection.writeWithMetadata(items) } @@ -128,7 +128,7 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = [], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { let items = zipToWrite(self, metadata) return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } @@ -144,7 +144,7 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?] = []) -> NSOperation { + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> NSOperation { let items = zipToWrite(self, metadata) return NSBlockOperation { connection.writeWithMetadata(items) } } From 0480a120245e3b51d492168264b80f57e1572971 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Fri, 9 Sep 2016 21:07:27 -0700 Subject: [PATCH 12/54] update tests --- Tests/Shared/Models.swift | 23 +- Tests/Shared/ObjectWithNoMetadataTests.swift | 13 - .../ObjectWithObjectMetadataTests.swift | 207 ++++++++-------- .../Shared/ObjectWithValueMetadataTests.swift | 211 ++++++++--------- Tests/Shared/ReadWriteTests.swift | 15 +- Tests/Shared/ValueWithNoMetadataTests.swift | 13 - .../Shared/ValueWithObjectMetadataTests.swift | 223 +++++++++--------- .../Shared/ValueWithValueMetadataTests.swift | 223 +++++++++--------- Tests/Shared/YapDatabaseExtensionsTests.swift | 26 +- 9 files changed, 473 insertions(+), 481 deletions(-) diff --git a/Tests/Shared/Models.swift b/Tests/Shared/Models.swift index 1994c7b..22a2efa 100644 --- a/Tests/Shared/Models.swift +++ b/Tests/Shared/Models.swift @@ -31,13 +31,11 @@ public struct Product: Identifiable, Equatable { } } - public var metadata: Metadata? = .None public let identifier: Identifier internal let name: String internal let barcode: Barcode - public init(metadata: Metadata? = .None, identifier: Identifier, name: String, barcode: Barcode) { - self.metadata = metadata + public init(identifier: Identifier, name: String, barcode: Barcode) { self.identifier = identifier self.name = name self.barcode = barcode @@ -46,7 +44,6 @@ public struct Product: Identifiable, Equatable { public struct Inventory: Identifiable, Equatable { let product: Product - public var metadata: NSNumber? = .None public var identifier: Identifier { return product.identifier @@ -77,14 +74,12 @@ public class NamedEntity: NSObject, NSCoding { public class Person: NamedEntity { } public class Employee: NamedEntity { - public var metadata: NSDate? = .None } public class Manager: NamedEntity { public struct Metadata: Equatable { public let numberOfDirectReports: Int } - public var metadata: Metadata? = .None } // MARK: - Equatable @@ -109,7 +104,7 @@ public func == (a: Product.Metadata, b: Product.Metadata) -> Bool { } public func == (a: Inventory, b: Inventory) -> Bool { - return (a.product == b.product) && (a.metadata == b.metadata) + return (a.product == b.product) } public func == (a: NamedEntity, b: NamedEntity) -> Bool { @@ -140,6 +135,18 @@ extension Inventory: Hashable { } } +extension Product.Metadata: Hashable { + public var hashValue: Int { + return categoryIdentifier.hashValue + } +} + +extension Manager.Metadata: Hashable { + public var hashValue: Int { + return numberOfDirectReports.hashValue + } +} + extension NamedEntity { public override var description: String { @@ -352,7 +359,7 @@ public class InventoryCoder: NSObject, NSCoding, CodingType { public required init?(coder aDecoder: NSCoder) { let product = Product.decode(aDecoder.decodeObjectForKey("product")) - value = Inventory(product: product!, metadata: .None) + value = Inventory(product: product!) } public func encodeWithCoder(aCoder: NSCoder) { diff --git a/Tests/Shared/ObjectWithNoMetadataTests.swift b/Tests/Shared/ObjectWithNoMetadataTests.swift index ce6fe18..5c125d6 100644 --- a/Tests/Shared/ObjectWithNoMetadataTests.swift +++ b/Tests/Shared/ObjectWithNoMetadataTests.swift @@ -112,7 +112,6 @@ class ObjectWithNoMetadataTests: XCTestCase { } XCTAssertEqual(readTransaction.didReadAtIndex, index) XCTAssertEqual(result.identifier, item.identifier) - XCTAssertNil(result.metadata) return true } @@ -135,18 +134,6 @@ class ObjectWithNoMetadataTests: XCTestCase { } } -class Base_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { - - func test__metadata_is_nil() { - XCTAssertNil(item.metadata) - } - - func test__metadata_cannot_be_set() { - item.metadata = Void() - XCTAssertNil(item.metadata) - } -} - class Functional_Read_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { // Functional API - ReadTransactionType - Reading diff --git a/Tests/Shared/ObjectWithObjectMetadataTests.swift b/Tests/Shared/ObjectWithObjectMetadataTests.swift index a4f71fb..a91ec71 100644 --- a/Tests/Shared/ObjectWithObjectMetadataTests.swift +++ b/Tests/Shared/ObjectWithObjectMetadataTests.swift @@ -13,12 +13,15 @@ import XCTest class ObjectWithObjectMetadataTests: XCTestCase { typealias TypeUnderTest = Employee + typealias MetadataTypeUnderTest = NSDate var item: TypeUnderTest! + var metadata: MetadataTypeUnderTest! var index: YapDB.Index! var key: String! var items: [TypeUnderTest]! + var metadatas: [MetadataTypeUnderTest?]! var indexes: [YapDB.Index]! var keys: [String]! @@ -56,9 +59,11 @@ class ObjectWithObjectMetadataTests: XCTestCase { override func tearDown() { item = nil + metadata = nil index = nil key = nil items = nil + metadatas = nil indexes = nil keys = nil @@ -73,55 +78,56 @@ class ObjectWithObjectMetadataTests: XCTestCase { func createPersistables() { item = TypeUnderTest(id: "beatle-1", name: "John") - item.metadata = NSDate() + metadata = NSDate() items = [ item, TypeUnderTest(id: "beatle-2", name: "Paul"), TypeUnderTest(id: "beatle-3", name: "George"), TypeUnderTest(id: "beatle-4", name: "Ringo") ] - items.suffixFrom(1).forEach { $0.metadata = NSDate() } + metadatas = [metadata] + items.suffixFrom(1).forEach { _ in metadatas.append(NSDate()) } } func configureForReadingSingle() { readTransaction.object = item - readTransaction.metadata = item.metadata + readTransaction.metadata = metadata } func configureForReadingMultiple() { readTransaction.objects = items - readTransaction.metadatas = items.map { $0.metadata } + readTransaction.metadatas = metadatas.map { $0 } readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: TypeUnderTest) { - XCTAssertEqual(result.identifier, item.identifier) + func checkTransactionDidWriteItem(result: (TypeUnderTest, MetadataTypeUnderTest?)) { + XCTAssertEqual(result.0.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSDate, item.metadata) + XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSDate, metadata) } - func checkTransactionDidWriteItems(result: [TypeUnderTest]) { + func checkTransactionDidWriteItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) - XCTAssertEqual(Set(result), Set(items)) + XCTAssertEqual(Set(result.map({$0.0})), Set(items)) } - func checkTransactionDidReadItem(result: TypeUnderTest?) -> Bool { + func checkTransactionDidReadItem(result: (TypeUnderTest, MetadataTypeUnderTest?)?) -> Bool { guard let result = result else { return false } XCTAssertEqual(readTransaction.didReadAtIndex, index) - XCTAssertEqual(result.identifier, item.identifier) + XCTAssertEqual(result.0.identifier, item.identifier) XCTAssertEqual(readTransaction.didReadMetadataAtIndex, index) - XCTAssertEqual(result.metadata, item.metadata) + XCTAssertEqual(result.1, metadata) return true } - func checkTransactionDidReadItems(result: [TypeUnderTest]) -> Bool { + func checkTransactionDidReadItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) -> Bool { if result.isEmpty { return false } @@ -145,7 +151,7 @@ class ObjectWithObjectMetadataTests: XCTestCase { class Base_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTests { func test__metadata_is_not_nil() { - XCTAssertNotNil(item.metadata) + XCTAssertNotNil(metadata) } } @@ -155,116 +161,116 @@ class Functional_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTes func test__transaction__read_at_index_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readAtIndex(index))) + XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readWithMetadataAtIndex(index))) } func test__transaction__read_at_index_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readAtIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readWithMetadataAtIndex(index))) } func test__transaction__read_at_indexes_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readAtIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataAtIndexes(indexes))) } func test__transaction__read_at_indexes_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readAtIndexes(Set(indexes)))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataAtIndexes(Set(indexes)))) } func test__transaction__read_at_indexes_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readAtIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readWithMetadataAtIndexes(indexes))) } func test__transaction__read_by_key_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readByKey(key))) + XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readWithMetadataByKey(key))) } func test__transaction__read_by_key_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readByKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readWithMetadataByKey(key))) } func test__transaction__read_by_keys_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readByKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataByKeys(keys))) } func test__transaction__read_by_keys_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readByKeys(Set(keys)))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataByKeys(Set(keys)))) } func test__transaction__read_by_keys_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readByKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readWithMetadataByKeys(keys))) } func test__transaction__read_all_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readAll())) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataAll())) } // Functional API - ConnectionType - Reading func test__connection__read_at_index_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.readAtIndex(index))) + XCTAssertTrue(checkTransactionDidReadItem(connection.readWithMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_index_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.readAtIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(connection.readWithMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_indexes_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readAtIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_indexes_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readAtIndexes(Set(indexes)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataAtIndexes(Set(indexes)))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_indexes_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.readAtIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(connection.readWithMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_key_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.readByKey(key))) + XCTAssertTrue(checkTransactionDidReadItem(connection.readWithMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_key_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.readByKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(connection.readWithMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_keys_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readByKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_keys_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readByKeys(Set(keys)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataByKeys(Set(keys)))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_keys_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.readByKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(connection.readWithMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__connection__read_all_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readAll())) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataAll())) XCTAssertTrue(connection.didRead) } } @@ -272,38 +278,29 @@ class Functional_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTes class Functional_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTests { func test__transaction__write_item() { - checkTransactionDidWriteItem(writeTransaction.write(item)) + checkTransactionDidWriteItem(writeTransaction.writeWithMetadata((item, metadata))) } func test__transaction__write_items() { - checkTransactionDidWriteItems(writeTransaction.write(items)) - } - - func test__transaction__write_items_2() { - checkTransactionDidWriteItems(writeTransaction.write(Set(items))) + checkTransactionDidWriteItems(writeTransaction.writeWithMetadata(zipToWrite(items, metadatas))) } // MARK: - Functional API - Connection - Writing func test__connection__write_item() { - checkTransactionDidWriteItem(connection.write(item)) + checkTransactionDidWriteItem(connection.writeWithMetadata((item, metadata))) XCTAssertTrue(connection.didWrite) } func test__connection__write_items() { - checkTransactionDidWriteItems(connection.write(items)) - XCTAssertTrue(connection.didWrite) - } - - func test__connection__write_items_2() { - checkTransactionDidWriteItems(connection.write(Set(items))) + checkTransactionDidWriteItems(connection.writeWithMetadata(zipToWrite(items, metadatas))) XCTAssertTrue(connection.didWrite) } func test__connection__async_write_item() { - var result: TypeUnderTest! + var result: (TypeUnderTest, MetadataTypeUnderTest?)! let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWrite(item) { tmp in + connection.asyncWriteWithMetadata((item, metadata)) { tmp in result = tmp expectation.fulfill() } @@ -313,9 +310,9 @@ class Functional_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe } func test__connection__async_write_items() { - var result: [TypeUnderTest] = [] + var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWrite(items) { received in + connection.asyncWriteWithMetadata(zipToWrite(items, metadatas)) { received in result = received expectation.fulfill() } @@ -382,45 +379,45 @@ class Curried_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTests func test__curried__read_at_index_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readAtIndex(index)))) + XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataAtIndex(index)))) XCTAssertTrue(connection.didRead) } func test__curried__read_at_index_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readAtIndex(index)))) + XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataAtIndex(index)))) XCTAssertTrue(connection.didRead) } func test__curried__read_at_indexes_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readAtIndexes(indexes)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataAtIndexes(indexes)))) XCTAssertTrue(connection.didRead) } func test__curried__read_at_indexes_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readAtIndexes(indexes)))) + XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataAtIndexes(indexes)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_key_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readByKey(key)))) + XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataByKey(key)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_key_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readByKey(key)))) + XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataByKey(key)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_keys_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readByKeys(keys)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataByKeys(keys)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_keys_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readByKeys(keys)))) + XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataByKeys(keys)))) XCTAssertTrue(connection.didRead) } } @@ -428,7 +425,7 @@ class Curried_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTests class Curried_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTests { func test__curried__write() { - checkTransactionDidWriteItem(connection.write(item.write())) + checkTransactionDidWriteItem(connection.write(item.writeWithMetadata(metadata))) XCTAssertTrue(connection.didWrite) } } @@ -440,69 +437,69 @@ class Persistable_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe func test__reader__in_transaction_at_index() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, atIndex: index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, atIndex: index))) } func test__reader__in_transaction_at_index_2() { configureForReadingSingle() reader = Read(readTransaction) - let atIndex = reader.inTransactionAtIndex(readTransaction) + let atIndex: YapDB.Index -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionAtIndex(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(atIndex(index))) } func test__reader__at_index_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction = reader.atIndexInTransaction(index) + let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataAtIndexInTransaction(index) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } func test__reader__at_indexes_in_transaction_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.atIndexesInTransaction(indexes)(readTransaction))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAtIndexesInTransaction(indexes)(readTransaction))) } func test__reader__at_indexes_in_transaction_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.atIndexesInTransaction(indexes)(readTransaction))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAtIndexesInTransaction(indexes)(readTransaction))) } func test__reader__in_transaction_by_key() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, byKey: key))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, byKey: key))) } func test__reader__in_transaction_by_key_2() { configureForReadingSingle() reader = Read(readTransaction) - let byKey = reader.inTransactionByKey(readTransaction) + let byKey: String -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionByKey(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(byKey(key))) } func test__reader__by_key_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction = reader.byKeyInTransaction(key) + let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataByKeyInTransaction(key) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } func test__reader__by_keys_in_transaction_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeysInTransaction(keys)(readTransaction))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeysInTransaction(keys)(readTransaction))) } func test__reader__by_keys_in_transaction_with_items_with_keys() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeysInTransaction()(readTransaction))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeysInTransaction()(readTransaction))) } func test__reader__by_keys_in_transaction_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.byKeysInTransaction(keys)(readTransaction))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataByKeysInTransaction(keys)(readTransaction))) } // Reading - With Transaction @@ -510,66 +507,66 @@ class Persistable_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe func test__reader_with_transaction__at_index_with_item() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, atIndex: index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, atIndex: index))) } func test__reader_with_transaction__at_index_with_no_item() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItem(reader.atIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataAtIndex(index))) } func test__reader_with_transaction__at_indexes_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) } func test__reader_with_transaction__at_indexes_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) } func test__reader_with_transaction__by_key_with_item() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, atIndex: index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, atIndex: index))) } func test__reader_with_transaction__by_key_with_no_item() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItem(reader.byKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataByKey(key))) } func test__reader_with_transaction__by_keys_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) } func test__reader_with_transaction__by_keys_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) } func test__reader_with_transaction__all_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.all())) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } func test__reader_with_transaction__all_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.all())) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } func test__reader_with_transaction__filter() { configureForReadingSingle() reader = Read(readTransaction) - let (items, missing) = reader.filterExisting(keys) + let (items, missing): ([(TypeUnderTest, MetadataTypeUnderTest?)], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.identifier }, items.prefixUpTo(1).map { $0.identifier }) + XCTAssertEqual(items.map { $0.0.identifier }, items.prefixUpTo(1).map { $0.0.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -578,66 +575,66 @@ class Persistable_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe func test__reader_with_connection__at_index_with_item() { configureForReadingSingle() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItem(reader.atIndex(index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__at_index_with_no_item() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItem(reader.atIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__at_indexes_with_items() { configureForReadingMultiple() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__at_indexes_with_no_items() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_key_with_item() { configureForReadingSingle() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItem(reader.byKey(key))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_key_with_no_item() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItem(reader.byKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_keys_with_items() { configureForReadingMultiple() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_keys_with_no_items() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__all_with_items() { configureForReadingMultiple() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItems(reader.all())) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } func test__reader_with_connection__all_with_no_items() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItems(reader.all())) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } @@ -657,19 +654,19 @@ class Persistable_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe class Persistable_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTests { func test__item_persistable__write_using_transaction() { - checkTransactionDidWriteItem(item.write(writeTransaction)) + checkTransactionDidWriteItem(item.writeWithMetadata(writeTransaction, metadata: metadata)) } func test__item_persistable__write_using_connection() { - checkTransactionDidWriteItem(item.write(connection)) + checkTransactionDidWriteItem(item.writeWithMetadata(connection, metadata: metadata)) XCTAssertTrue(connection.didWrite) } func test__item_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: TypeUnderTest! = nil + var result: (TypeUnderTest, MetadataTypeUnderTest?)! = nil - item.asyncWrite(connection) { tmp in + item.asyncWriteWithMetadata(connection, metadata: metadata) { tmp in result = tmp expectation.fulfill() } @@ -681,7 +678,7 @@ class Persistable_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataT func test__item_persistable__write_using_opertion() { let expectation = expectationWithDescription("Test: \(#function)") - let operation = item.writeOperation(connection) + let operation = item.writeWithMetadataOperation(connection, metadata: metadata) operation.completionBlock = { expectation.fulfill() } @@ -691,24 +688,24 @@ class Persistable_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataT XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSDate, item.metadata) + XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSDate, metadata) XCTAssertTrue(connection.didWrite) } func test__items_persistable__write_using_transaction() { - checkTransactionDidWriteItems(items.write(writeTransaction)) + checkTransactionDidWriteItems(items.writeWithMetadata(writeTransaction, metadata: metadatas)) } func test__items_persistable__write_using_connection() { - checkTransactionDidWriteItems(items.write(connection)) + checkTransactionDidWriteItems(items.writeWithMetadata(connection, metadata: metadatas)) XCTAssertTrue(connection.didWrite) } func test__items_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: [TypeUnderTest] = [] + var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] - items.asyncWrite(connection) { tmp in + items.asyncWriteWithMetadata(connection, metadata: metadatas) { tmp in result = tmp expectation.fulfill() } diff --git a/Tests/Shared/ObjectWithValueMetadataTests.swift b/Tests/Shared/ObjectWithValueMetadataTests.swift index ddbe249..919eec4 100644 --- a/Tests/Shared/ObjectWithValueMetadataTests.swift +++ b/Tests/Shared/ObjectWithValueMetadataTests.swift @@ -13,12 +13,15 @@ import XCTest class ObjectWithValueMetadataTests: XCTestCase { typealias TypeUnderTest = Manager + typealias MetadataTypeUnderTest = Manager.Metadata var item: TypeUnderTest! + var metadata: MetadataTypeUnderTest! var index: YapDB.Index! var key: String! var items: [TypeUnderTest]! + var metadatas: [MetadataTypeUnderTest?]! var indexes: [YapDB.Index]! var keys: [String]! @@ -56,9 +59,11 @@ class ObjectWithValueMetadataTests: XCTestCase { override func tearDown() { item = nil + metadata = nil index = nil key = nil items = nil + metadatas = nil indexes = nil keys = nil @@ -73,55 +78,60 @@ class ObjectWithValueMetadataTests: XCTestCase { func createPersistables() { item = TypeUnderTest(id: "beatle-1", name: "John") - item.metadata = TypeUnderTest.Metadata(numberOfDirectReports: 4) + metadata = MetadataTypeUnderTest(numberOfDirectReports: 4) items = [ item, TypeUnderTest(id: "beatle-2", name: "Paul"), TypeUnderTest(id: "beatle-3", name: "George"), TypeUnderTest(id: "beatle-4", name: "Ringo") ] - items.suffixFrom(1).forEach { $0.metadata = TypeUnderTest.Metadata(numberOfDirectReports: 1) } + metadatas = [ + metadata, + MetadataTypeUnderTest(numberOfDirectReports: 3), + MetadataTypeUnderTest(numberOfDirectReports: 2), + MetadataTypeUnderTest(numberOfDirectReports: 1) + ] } func configureForReadingSingle() { readTransaction.object = item - readTransaction.metadata = item.metadata?.encoded + readTransaction.metadata = metadata?.encoded } func configureForReadingMultiple() { readTransaction.objects = items - readTransaction.metadatas = items.map { $0.metadata?.encoded } + readTransaction.metadatas = metadatas.map { $0?.encoded } readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: TypeUnderTest) { - XCTAssertEqual(result.identifier, item.identifier) + func checkTransactionDidWriteItem(result: (TypeUnderTest, MetadataTypeUnderTest?)) { + XCTAssertEqual(result.0.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertEqual(TypeUnderTest.MetadataType.decode(writeTransaction.didWriteAtIndexes[0].2), item.metadata) + XCTAssertEqual(MetadataTypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].2), metadata) } - func checkTransactionDidWriteItems(result: [TypeUnderTest]) { + func checkTransactionDidWriteItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) - XCTAssertEqual(Set(result), Set(items)) + XCTAssertEqual(Set(result.map({$0.0})), Set(items)) } - func checkTransactionDidReadItem(result: TypeUnderTest?) -> Bool { + func checkTransactionDidReadItem(result: (TypeUnderTest, MetadataTypeUnderTest?)?) -> Bool { guard let result = result else { return false } XCTAssertEqual(readTransaction.didReadAtIndex, index) - XCTAssertEqual(result.identifier, item.identifier) + XCTAssertEqual(result.0.identifier, item.identifier) XCTAssertEqual(readTransaction.didReadMetadataAtIndex, index) - XCTAssertEqual(result.metadata, item.metadata) + XCTAssertEqual(result.1, metadata) return true } - func checkTransactionDidReadItems(result: [TypeUnderTest]) -> Bool { + func checkTransactionDidReadItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) -> Bool { if result.isEmpty { return false } @@ -145,7 +155,7 @@ class ObjectWithValueMetadataTests: XCTestCase { class Base_ObjectWithValueMetadataTests: ObjectWithValueMetadataTests { func test__metadata_is_not_nil() { - XCTAssertNotNil(item.metadata) + XCTAssertNotNil(metadata) } } @@ -155,116 +165,116 @@ class Functional_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTests func test__transaction__read_at_index_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readAtIndex(index))) + XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readWithMetadataAtIndex(index))) } func test__transaction__read_at_index_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readAtIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readWithMetadataAtIndex(index))) } func test__transaction__read_at_indexes_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readAtIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataAtIndexes(indexes))) } func test__transaction__read_at_indexes_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readAtIndexes(Set(indexes)))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataAtIndexes(Set(indexes)))) } func test__transaction__read_at_indexes_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readAtIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readWithMetadataAtIndexes(indexes))) } func test__transaction__read_by_key_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readByKey(key))) + XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readWithMetadataByKey(key))) } func test__transaction__read_by_key_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readByKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readWithMetadataByKey(key))) } func test__transaction__read_by_keys_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readByKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataByKeys(keys))) } func test__transaction__read_by_keys_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readByKeys(Set(keys)))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataByKeys(Set(keys)))) } func test__transaction__read_by_keys_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readByKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readWithMetadataByKeys(keys))) } func test__transaction__read_all_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readAll())) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataAll())) } // Functional API - ConnectionType - Reading func test__connection__read_at_index_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.readAtIndex(index))) + XCTAssertTrue(checkTransactionDidReadItem(connection.readWithMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_index_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.readAtIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(connection.readWithMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_indexes_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readAtIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_indexes_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readAtIndexes(Set(indexes)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataAtIndexes(Set(indexes)))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_indexes_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.readAtIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(connection.readWithMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_key_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.readByKey(key))) + XCTAssertTrue(checkTransactionDidReadItem(connection.readWithMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_key_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.readByKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(connection.readWithMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_keys_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readByKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_keys_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readByKeys(Set(keys)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataByKeys(Set(keys)))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_keys_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.readByKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(connection.readWithMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__connection__read_all_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readAll())) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataAll())) XCTAssertTrue(connection.didRead) } } @@ -272,38 +282,29 @@ class Functional_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTests class Functional_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTests { func test__transaction__write_item() { - checkTransactionDidWriteItem(writeTransaction.write(item)) + checkTransactionDidWriteItem(writeTransaction.writeWithMetadata((item, metadata))) } func test__transaction__write_items() { - checkTransactionDidWriteItems(writeTransaction.write(items)) - } - - func test__transaction__write_items_2() { - checkTransactionDidWriteItems(writeTransaction.write(Set(items))) + checkTransactionDidWriteItems(writeTransaction.writeWithMetadata(zipToWrite(items, metadatas))) } // MARK: - Functional API - Connection - Writing func test__connection__write_item() { - checkTransactionDidWriteItem(connection.write(item)) + checkTransactionDidWriteItem(connection.writeWithMetadata((item, metadata))) XCTAssertTrue(connection.didWrite) } func test__connection__write_items() { - checkTransactionDidWriteItems(connection.write(items)) - XCTAssertTrue(connection.didWrite) - } - - func test__connection__write_items_2() { - checkTransactionDidWriteItems(connection.write(Set(items))) + checkTransactionDidWriteItems(connection.writeWithMetadata(zipToWrite(items, metadatas))) XCTAssertTrue(connection.didWrite) } func test__connection__async_write_item() { - var result: TypeUnderTest! + var result: (TypeUnderTest, MetadataTypeUnderTest?)! let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWrite(item) { tmp in + connection.asyncWriteWithMetadata((item, metadata)) { tmp in result = tmp expectation.fulfill() } @@ -313,9 +314,9 @@ class Functional_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest } func test__connection__async_write_items() { - var result: [TypeUnderTest] = [] + var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWrite(items) { received in + connection.asyncWriteWithMetadata(zipToWrite(items, metadatas)) { received in result = received expectation.fulfill() } @@ -382,45 +383,45 @@ class Curried_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTests { func test__curried__read_at_index_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readAtIndex(index)))) + XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataAtIndex(index)))) XCTAssertTrue(connection.didRead) } func test__curried__read_at_index_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readAtIndex(index)))) + XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataAtIndex(index)))) XCTAssertTrue(connection.didRead) } func test__curried__read_at_indexes_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readAtIndexes(indexes)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataAtIndexes(indexes)))) XCTAssertTrue(connection.didRead) } func test__curried__read_at_indexes_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readAtIndexes(indexes)))) + XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataAtIndexes(indexes)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_key_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readByKey(key)))) + XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataByKey(key)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_key_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readByKey(key)))) + XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataByKey(key)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_keys_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readByKeys(keys)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataByKeys(keys)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_keys_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readByKeys(keys)))) + XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataByKeys(keys)))) XCTAssertTrue(connection.didRead) } } @@ -428,7 +429,7 @@ class Curried_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTests { class Curried_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTests { func test__curried__write() { - checkTransactionDidWriteItem(connection.write(item.write())) + checkTransactionDidWriteItem(connection.write(item.writeWithMetadata(metadata))) XCTAssertTrue(connection.didWrite) } } @@ -440,69 +441,69 @@ class Persistable_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest func test__reader__in_transaction_at_index() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, atIndex: index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, atIndex: index))) } func test__reader__in_transaction_at_index_2() { configureForReadingSingle() reader = Read(readTransaction) - let atIndex = reader.inTransactionAtIndex(readTransaction) + let atIndex: YapDB.Index -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionAtIndex(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(atIndex(index))) } func test__reader__at_index_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction = reader.atIndexInTransaction(index) + let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataAtIndexInTransaction(index) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } func test__reader__at_indexes_in_transaction_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.atIndexesInTransaction(indexes)(readTransaction))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAtIndexesInTransaction(indexes)(readTransaction))) } func test__reader__at_indexes_in_transaction_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.atIndexesInTransaction(indexes)(readTransaction))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAtIndexesInTransaction(indexes)(readTransaction))) } func test__reader__in_transaction_by_key() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, byKey: key))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, byKey: key))) } func test__reader__in_transaction_by_key_2() { configureForReadingSingle() reader = Read(readTransaction) - let byKey = reader.inTransactionByKey(readTransaction) + let byKey: String -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionByKey(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(byKey(key))) } func test__reader__by_key_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction = reader.byKeyInTransaction(key) + let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataByKeyInTransaction(key) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } func test__reader__by_keys_in_transaction_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeysInTransaction(keys)(readTransaction))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeysInTransaction(keys)(readTransaction))) } func test__reader__by_keys_in_transaction_with_items_with_keys() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeysInTransaction()(readTransaction))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeysInTransaction()(readTransaction))) } func test__reader__by_keys_in_transaction_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.byKeysInTransaction(keys)(readTransaction))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataByKeysInTransaction(keys)(readTransaction))) } // Reading - With Transaction @@ -510,66 +511,66 @@ class Persistable_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest func test__reader_with_transaction__at_index_with_item() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, atIndex: index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, atIndex: index))) } func test__reader_with_transaction__at_index_with_no_item() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItem(reader.atIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataAtIndex(index))) } func test__reader_with_transaction__at_indexes_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) } func test__reader_with_transaction__at_indexes_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) } func test__reader_with_transaction__by_key_with_item() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, atIndex: index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, atIndex: index))) } func test__reader_with_transaction__by_key_with_no_item() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItem(reader.byKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataByKey(key))) } func test__reader_with_transaction__by_keys_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) } func test__reader_with_transaction__by_keys_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) } func test__reader_with_transaction__all_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.all())) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } func test__reader_with_transaction__all_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.all())) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } func test__reader_with_transaction__filter() { configureForReadingSingle() reader = Read(readTransaction) - let (items, missing) = reader.filterExisting(keys) + let (items, missing): ([(TypeUnderTest, MetadataTypeUnderTest?)], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.identifier }, items.prefixUpTo(1).map { $0.identifier }) + XCTAssertEqual(items.map { $0.0.identifier }, items.prefixUpTo(1).map { $0.0.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -578,66 +579,66 @@ class Persistable_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest func test__reader_with_connection__at_index_with_item() { configureForReadingSingle() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItem(reader.atIndex(index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__at_index_with_no_item() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItem(reader.atIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__at_indexes_with_items() { configureForReadingMultiple() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__at_indexes_with_no_items() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_key_with_item() { configureForReadingSingle() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItem(reader.byKey(key))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_key_with_no_item() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItem(reader.byKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_keys_with_items() { configureForReadingMultiple() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_keys_with_no_items() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__all_with_items() { configureForReadingMultiple() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItems(reader.all())) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } func test__reader_with_connection__all_with_no_items() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItems(reader.all())) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } @@ -657,19 +658,19 @@ class Persistable_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest class Persistable_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTests { func test__item_persistable__write_using_transaction() { - checkTransactionDidWriteItem(item.write(writeTransaction)) + checkTransactionDidWriteItem(item.writeWithMetadata(writeTransaction, metadata: metadata)) } func test__item_persistable__write_using_connection() { - checkTransactionDidWriteItem(item.write(connection)) + checkTransactionDidWriteItem(item.writeWithMetadata(connection, metadata: metadata)) XCTAssertTrue(connection.didWrite) } func test__item_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: TypeUnderTest! = nil + var result: (TypeUnderTest, MetadataTypeUnderTest?)! = nil - item.asyncWrite(connection) { tmp in + item.asyncWriteWithMetadata(connection, metadata: metadata) { tmp in result = tmp expectation.fulfill() } @@ -681,7 +682,7 @@ class Persistable_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTes func test__item_persistable__write_using_opertion() { let expectation = expectationWithDescription("Test: \(#function)") - let operation = item.writeOperation(connection) + let operation = item.writeWithMetadataOperation(connection, metadata: metadata) operation.completionBlock = { expectation.fulfill() } @@ -691,24 +692,24 @@ class Persistable_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTes XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertEqual(TypeUnderTest.MetadataType.decode(writeTransaction.didWriteAtIndexes[0].2), item.metadata) + XCTAssertEqual(MetadataTypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].2), metadata) XCTAssertTrue(connection.didWrite) } func test__items_persistable__write_using_transaction() { - checkTransactionDidWriteItems(items.write(writeTransaction)) + checkTransactionDidWriteItems(items.writeWithMetadata(writeTransaction, metadata: metadatas)) } func test__items_persistable__write_using_connection() { - checkTransactionDidWriteItems(items.write(connection)) + checkTransactionDidWriteItems(items.writeWithMetadata(connection, metadata: metadatas)) XCTAssertTrue(connection.didWrite) } func test__items_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: [TypeUnderTest] = [] + var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] - items.asyncWrite(connection) { tmp in + items.asyncWriteWithMetadata(connection, metadata: metadatas) { tmp in result = tmp expectation.fulfill() } diff --git a/Tests/Shared/ReadWriteTests.swift b/Tests/Shared/ReadWriteTests.swift index ae0f920..f1c14c3 100644 --- a/Tests/Shared/ReadWriteTests.swift +++ b/Tests/Shared/ReadWriteTests.swift @@ -10,10 +10,12 @@ import YapDatabase class ReadWriteBaseTests: XCTestCase { var item: Employee! + var metadata: NSDate! var index: YapDB.Index! var key: String! var items: [Employee]! + var metadatas: [NSDate?]! var indexes: [YapDB.Index]! var keys: [String]! @@ -29,9 +31,11 @@ class ReadWriteBaseTests: XCTestCase { override func tearDown() { item = nil + metadata = nil index = nil key = nil items = nil + metadatas = nil indexes = nil keys = nil super.tearDown() @@ -39,18 +43,23 @@ class ReadWriteBaseTests: XCTestCase { func createPersistables() { item = Employee(id: "beatle-1", name: "John") - item.metadata = NSDate() + metadata = NSDate() items = [ item, Employee(id: "beatle-2", name: "Paul"), Employee(id: "beatle-3", name: "George"), Employee(id: "beatle-4", name: "Ringo") ] - items.suffixFrom(1).forEach { $0.metadata = NSDate() } + metadatas = [ + metadata, + NSDate(), + NSDate(), + NSDate() + ] } func writeItemsToDatabase(db: YapDatabase) { - db.makeNewConnection().write(items) + db.makeNewConnection().writeWithMetadata(zipToWrite(items, metadatas)) } } diff --git a/Tests/Shared/ValueWithNoMetadataTests.swift b/Tests/Shared/ValueWithNoMetadataTests.swift index 7c61aec..dc15538 100644 --- a/Tests/Shared/ValueWithNoMetadataTests.swift +++ b/Tests/Shared/ValueWithNoMetadataTests.swift @@ -114,7 +114,6 @@ class ValueWithNoMetadataTests: XCTestCase { } XCTAssertEqual(readTransaction.didReadAtIndex, index) XCTAssertEqual(result.identifier, item.identifier) - XCTAssertNil(result.metadata) return true } @@ -137,18 +136,6 @@ class ValueWithNoMetadataTests: XCTestCase { } } -class Base_ValueWithNoMetadataTests: ValueWithNoMetadataTests { - - func test__metadata_is_nil() { - XCTAssertNil(item.metadata) - } - - func test__metadata_cannot_be_set() { - item.metadata = Void() - XCTAssertNil(item.metadata) - } -} - class Functional_Read_ValueWithNoMetadataTests: ValueWithNoMetadataTests { // Functional API - ReadTransactionType - Reading diff --git a/Tests/Shared/ValueWithObjectMetadataTests.swift b/Tests/Shared/ValueWithObjectMetadataTests.swift index 185e02f..80e9b14 100644 --- a/Tests/Shared/ValueWithObjectMetadataTests.swift +++ b/Tests/Shared/ValueWithObjectMetadataTests.swift @@ -13,12 +13,15 @@ import XCTest class ValueWithObjectMetadataTests: XCTestCase { typealias TypeUnderTest = Inventory + typealias MetadataTypeUnderTest = NSNumber var item: TypeUnderTest! + var metadata: MetadataTypeUnderTest! var index: YapDB.Index! var key: String! var items: [TypeUnderTest]! + var metadatas: [MetadataTypeUnderTest?]! var indexes: [YapDB.Index]! var keys: [String]! @@ -56,9 +59,11 @@ class ValueWithObjectMetadataTests: XCTestCase { override func tearDown() { item = nil + metadata = nil index = nil key = nil items = nil + metadatas = nil indexes = nil keys = nil @@ -74,74 +79,77 @@ class ValueWithObjectMetadataTests: XCTestCase { func createPersistables() { let products = [ Product( - metadata: Product.Metadata(categoryIdentifier: 1), identifier: "vodka-123", name: "Belvidere", barcode: .UPCA(1, 2, 3, 4) ), Product( - metadata: Product.Metadata(categoryIdentifier: 2), identifier: "gin-123", name: "Boxer Gin", barcode: .UPCA(5, 10, 15, 20) ), Product( - metadata: Product.Metadata(categoryIdentifier: 3), identifier: "rum-123", name: "Mount Gay Rum", barcode: .UPCA(12, 24, 39, 48) ), Product( - metadata: Product.Metadata(categoryIdentifier: 2), identifier: "gin-234", name: "Monkey 47", barcode: .UPCA(31, 62, 93, 124) ) ] - items = products.map { TypeUnderTest(product: $0, metadata: NSNumber(integer: 12)) } + metadatas = [ + NSNumber(integer: 12), + NSNumber(integer: 13), + NSNumber(integer: 14), + NSNumber(integer: 15) + ] + items = products.map { TypeUnderTest(product: $0) } item = items[0] + metadata = metadatas[0] } func configureForReadingSingle() { readTransaction.object = item.encoded - readTransaction.metadata = item.metadata + readTransaction.metadata = metadata } func configureForReadingMultiple() { readTransaction.objects = items.encoded - readTransaction.metadatas = items.map { $0.metadata } + readTransaction.metadatas = metadatas.map { $0 } readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: TypeUnderTest) { - XCTAssertEqual(result.identifier, item.identifier) + func checkTransactionDidWriteItem(result: (TypeUnderTest, MetadataTypeUnderTest?)) { + XCTAssertEqual(result.0.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(TypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].1)!, item) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSNumber, item.metadata) + XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSNumber, metadata) } - func checkTransactionDidWriteItems(result: [TypeUnderTest]) { + func checkTransactionDidWriteItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) - XCTAssertEqual(Set(result), Set(items)) + XCTAssertEqual(Set(result.map({$0.0})), Set(items)) } - func checkTransactionDidReadItem(result: TypeUnderTest?) -> Bool { + func checkTransactionDidReadItem(result: (TypeUnderTest, MetadataTypeUnderTest?)?) -> Bool { XCTAssertEqual(readTransaction.didReadAtIndex, index) guard let result = result else { return false } XCTAssertEqual(readTransaction.didReadMetadataAtIndex, index) - XCTAssertEqual(result.identifier, item.identifier) - XCTAssertEqual(result.metadata, item.metadata) + XCTAssertEqual(result.0.identifier, item.identifier) + XCTAssertEqual(result.1, metadata) return true } - func checkTransactionDidReadItems(result: [TypeUnderTest]) -> Bool { + func checkTransactionDidReadItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) -> Bool { if result.isEmpty { return false } @@ -150,17 +158,17 @@ class ValueWithObjectMetadataTests: XCTestCase { return true } - func checkTransactionDidReadMetadataItem(result: TypeUnderTest.MetadataType?) -> Bool { + func checkTransactionDidReadMetadataItem(result: MetadataTypeUnderTest?) -> Bool { XCTAssertNil(readTransaction.didReadAtIndex) guard let result = result else { return false } XCTAssertEqual(readTransaction.didReadMetadataAtIndex, index) - XCTAssertEqual(result, item.metadata) + XCTAssertEqual(result, metadata) return true } - func checkTransactionDidReadMetadataItems(result: [TypeUnderTest.MetadataType]) -> Bool { + func checkTransactionDidReadMetadataItems(result: [MetadataTypeUnderTest]) -> Bool { XCTAssertTrue(readTransaction.didReadAtIndexes.isEmpty) if result.isEmpty { return false @@ -186,7 +194,7 @@ class ValueWithObjectMetadataTests: XCTestCase { class Base_ValueWithObjectMetadataTests: ValueWithObjectMetadataTests { func test__metadata_is_not_nil() { - XCTAssertNotNil(item.metadata) + XCTAssertNotNil(metadata) } } @@ -196,116 +204,116 @@ class Functional_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTests func test__transaction__read_at_index_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readAtIndex(index))) + XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readWithMetadataAtIndex(index))) } func test__transaction__read_at_index_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readAtIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readWithMetadataAtIndex(index))) } func test__transaction__read_at_indexes_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readAtIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataAtIndexes(indexes))) } func test__transaction__read_at_indexes_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readAtIndexes(Set(indexes)))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataAtIndexes(Set(indexes)))) } func test__transaction__read_at_indexes_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readAtIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readWithMetadataAtIndexes(indexes))) } func test__transaction__read_by_key_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readByKey(key))) + XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readWithMetadataByKey(key))) } func test__transaction__read_by_key_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readByKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readWithMetadataByKey(key))) } func test__transaction__read_by_keys_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readByKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataByKeys(keys))) } func test__transaction__read_by_keys_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readByKeys(Set(keys)))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataByKeys(Set(keys)))) } func test__transaction__read_by_keys_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readByKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readWithMetadataByKeys(keys))) } func test__transaction__read_all_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readAll())) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataAll())) } // Functional API - ConnectionType - Reading func test__connection__read_at_index_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.readAtIndex(index))) + XCTAssertTrue(checkTransactionDidReadItem(connection.readWithMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_index_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.readAtIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(connection.readWithMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_indexes_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readAtIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_indexes_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readAtIndexes(Set(indexes)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataAtIndexes(Set(indexes)))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_indexes_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.readAtIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(connection.readWithMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_key_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.readByKey(key))) + XCTAssertTrue(checkTransactionDidReadItem(connection.readWithMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_key_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.readByKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(connection.readWithMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_keys_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readByKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_keys_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readByKeys(Set(keys)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataByKeys(Set(keys)))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_keys_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.readByKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(connection.readWithMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__connection__read_all_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readAll())) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataAll())) XCTAssertTrue(connection.didRead) } } @@ -356,38 +364,29 @@ class Functional_Read_Metadata_ValueWithObjectMetadataTests: ValueWithObjectMeta class Functional_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTests { func test__transaction__write_item() { - checkTransactionDidWriteItem(writeTransaction.write(item)) + checkTransactionDidWriteItem(writeTransaction.writeWithMetadata((item, metadata))) } func test__transaction__write_items() { - checkTransactionDidWriteItems(writeTransaction.write(items)) - } - - func test__transaction__write_items_2() { - checkTransactionDidWriteItems(writeTransaction.write(Set(items))) + checkTransactionDidWriteItems(writeTransaction.writeWithMetadata(zipToWrite(items, metadatas))) } // MARK: - Functional API - Connection - Writing func test__connection__write_item() { - checkTransactionDidWriteItem(connection.write(item)) + checkTransactionDidWriteItem(connection.writeWithMetadata((item, metadata))) XCTAssertTrue(connection.didWrite) } func test__connection__write_items() { - checkTransactionDidWriteItems(connection.write(items)) - XCTAssertTrue(connection.didWrite) - } - - func test__connection__write_items_2() { - checkTransactionDidWriteItems(connection.write(Set(items))) + checkTransactionDidWriteItems(connection.writeWithMetadata(zipToWrite(items, metadatas))) XCTAssertTrue(connection.didWrite) } func test__connection__async_write_item() { - var result: TypeUnderTest! + var result: (TypeUnderTest, MetadataTypeUnderTest?)! let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWrite(item) { tmp in + connection.asyncWriteWithMetadata((item, metadata)) { tmp in result = tmp expectation.fulfill() } @@ -397,9 +396,9 @@ class Functional_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest } func test__connection__async_write_items() { - var result: [TypeUnderTest] = [] + var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWrite(items) { received in + connection.asyncWriteWithMetadata(zipToWrite(items, metadatas)) { received in result = received expectation.fulfill() } @@ -466,45 +465,45 @@ class Curried_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTests { func test__curried__read_at_index_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readAtIndex(index)))) + XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataAtIndex(index)))) XCTAssertTrue(connection.didRead) } func test__curried__read_at_index_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readAtIndex(index)))) + XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataAtIndex(index)))) XCTAssertTrue(connection.didRead) } func test__curried__read_at_indexes_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readAtIndexes(indexes)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataAtIndexes(indexes)))) XCTAssertTrue(connection.didRead) } func test__curried__read_at_indexes_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readAtIndexes(indexes)))) + XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataAtIndexes(indexes)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_key_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readByKey(key)))) + XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataByKey(key)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_key_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readByKey(key)))) + XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataByKey(key)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_keys_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readByKeys(keys)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataByKeys(keys)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_keys_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readByKeys(keys)))) + XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataByKeys(keys)))) XCTAssertTrue(connection.didRead) } } @@ -512,7 +511,7 @@ class Curried_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTests { class Curried_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTests { func test__curried__write() { - checkTransactionDidWriteItem(connection.write(item.write())) + checkTransactionDidWriteItem(connection.write(item.writeWithMetadata(metadata))) XCTAssertTrue(connection.didWrite) } } @@ -524,69 +523,69 @@ class Persistable_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest func test__reader__in_transaction_at_index() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, atIndex: index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, atIndex: index))) } func test__reader__in_transaction_at_index_2() { configureForReadingSingle() reader = Read(readTransaction) - let atIndex = reader.inTransactionAtIndex(readTransaction) + let atIndex: YapDB.Index -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionAtIndex(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(atIndex(index))) } func test__reader__at_index_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction = reader.atIndexInTransaction(index) + let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataAtIndexInTransaction(index) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } func test__reader__at_indexes_in_transaction_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.atIndexesInTransaction(indexes)(readTransaction))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAtIndexesInTransaction(indexes)(readTransaction))) } func test__reader__at_indexes_in_transaction_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.atIndexesInTransaction(indexes)(readTransaction))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAtIndexesInTransaction(indexes)(readTransaction))) } func test__reader__in_transaction_by_key() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, byKey: key))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, byKey: key))) } func test__reader__in_transaction_by_key_2() { configureForReadingSingle() reader = Read(readTransaction) - let byKey = reader.inTransactionByKey(readTransaction) + let byKey: String -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionByKey(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(byKey(key))) } func test__reader__by_key_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction = reader.byKeyInTransaction(key) + let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataByKeyInTransaction(key) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } func test__reader__by_keys_in_transaction_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeysInTransaction(keys)(readTransaction))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeysInTransaction(keys)(readTransaction))) } func test__reader__by_keys_in_transaction_with_items_with_keys() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeysInTransaction()(readTransaction))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeysInTransaction()(readTransaction))) } func test__reader__by_keys_in_transaction_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.byKeysInTransaction(keys)(readTransaction))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataByKeysInTransaction(keys)(readTransaction))) } // Reading - With Transaction @@ -594,66 +593,66 @@ class Persistable_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest func test__reader_with_transaction__at_index_with_item() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, atIndex: index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, atIndex: index))) } func test__reader_with_transaction__at_index_with_no_item() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItem(reader.atIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataAtIndex(index))) } func test__reader_with_transaction__at_indexes_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) } func test__reader_with_transaction__at_indexes_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) } func test__reader_with_transaction__by_key_with_item() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, atIndex: index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, atIndex: index))) } func test__reader_with_transaction__by_key_with_no_item() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItem(reader.byKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataByKey(key))) } func test__reader_with_transaction__by_keys_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) } func test__reader_with_transaction__by_keys_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) } func test__reader_with_transaction__all_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.all())) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } func test__reader_with_transaction__all_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.all())) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } func test__reader_with_transaction__filter() { configureForReadingSingle() reader = Read(readTransaction) - let (items, missing) = reader.filterExisting(keys) + let (items, missing): ([(TypeUnderTest, MetadataTypeUnderTest?)], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.identifier }, items.prefixUpTo(1).map { $0.identifier }) + XCTAssertEqual(items.map { $0.0.identifier }, items.prefixUpTo(1).map { $0.0.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -662,66 +661,66 @@ class Persistable_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest func test__reader_with_connection__at_index_with_item() { configureForReadingSingle() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItem(reader.atIndex(index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__at_index_with_no_item() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItem(reader.atIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__at_indexes_with_items() { configureForReadingMultiple() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__at_indexes_with_no_items() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_key_with_item() { configureForReadingSingle() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItem(reader.byKey(key))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_key_with_no_item() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItem(reader.byKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_keys_with_items() { configureForReadingMultiple() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_keys_with_no_items() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__all_with_items() { configureForReadingMultiple() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItems(reader.all())) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } func test__reader_with_connection__all_with_no_items() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItems(reader.all())) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } @@ -792,19 +791,19 @@ class Persistable_Read_Metadata_ValueWithObjectMetadataTests: ValueWithObjectMet class Persistable_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTests { func test__item_persistable__write_using_transaction() { - checkTransactionDidWriteItem(item.write(writeTransaction)) + checkTransactionDidWriteItem(item.writeWithMetadata(writeTransaction, metadata: metadata)) } func test__item_persistable__write_using_connection() { - checkTransactionDidWriteItem(item.write(connection)) + checkTransactionDidWriteItem(item.writeWithMetadata(connection, metadata: metadata)) XCTAssertTrue(connection.didWrite) } func test__item_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: TypeUnderTest! = nil + var result: (TypeUnderTest, MetadataTypeUnderTest?)! = nil - item.asyncWrite(connection) { tmp in + item.asyncWriteWithMetadata(connection, metadata: metadata) { tmp in result = tmp expectation.fulfill() } @@ -816,7 +815,7 @@ class Persistable_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTes func test__item_persistable__write_using_opertion() { let expectation = expectationWithDescription("Test: \(#function)") - let operation = item.writeOperation(connection) + let operation = item.writeWithMetadataOperation(connection, metadata: metadata) operation.completionBlock = { expectation.fulfill() } @@ -826,24 +825,24 @@ class Persistable_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTes XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(TypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].1)!, item) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSNumber, item.metadata) + XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSNumber, metadata) XCTAssertTrue(connection.didWrite) } func test__items_persistable__write_using_transaction() { - checkTransactionDidWriteItems(items.write(writeTransaction)) + checkTransactionDidWriteItems(items.writeWithMetadata(writeTransaction, metadata: metadatas)) } func test__items_persistable__write_using_connection() { - checkTransactionDidWriteItems(items.write(connection)) + checkTransactionDidWriteItems(items.writeWithMetadata(connection, metadata: metadatas)) XCTAssertTrue(connection.didWrite) } func test__items_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: [TypeUnderTest] = [] + var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] - items.asyncWrite(connection) { tmp in + items.asyncWriteWithMetadata(connection, metadata: metadatas) { tmp in result = tmp expectation.fulfill() } @@ -855,7 +854,7 @@ class Persistable_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTes func test__items_persistable__write_using_opertion() { let expectation = expectationWithDescription("Test: \(#function)") - let operation = items.writeOperation(connection) + let operation = items.writeWithMetadataOperation(connection, metadata: metadatas) operation.completionBlock = { expectation.fulfill() } diff --git a/Tests/Shared/ValueWithValueMetadataTests.swift b/Tests/Shared/ValueWithValueMetadataTests.swift index a22b05d..d6b4fd6 100644 --- a/Tests/Shared/ValueWithValueMetadataTests.swift +++ b/Tests/Shared/ValueWithValueMetadataTests.swift @@ -13,12 +13,15 @@ import XCTest class ValueWithValueMetadataTests: XCTestCase { typealias TypeUnderTest = Product + typealias MetadataTypeUnderTest = Product.Metadata var item: TypeUnderTest! + var metadata: MetadataTypeUnderTest! var index: YapDB.Index! var key: String! var items: [TypeUnderTest]! + var metadatas: [MetadataTypeUnderTest?]! var indexes: [YapDB.Index]! var keys: [String]! @@ -56,9 +59,11 @@ class ValueWithValueMetadataTests: XCTestCase { override func tearDown() { item = nil + metadata = nil index = nil key = nil items = nil + metadatas = nil indexes = nil keys = nil @@ -73,73 +78,76 @@ class ValueWithValueMetadataTests: XCTestCase { func createPersistables() { item = TypeUnderTest( - metadata: TypeUnderTest.Metadata(categoryIdentifier: 1), identifier: "vodka-123", name: "Belvidere", barcode: .UPCA(1, 2, 3, 4) ) + metadata = TypeUnderTest.Metadata(categoryIdentifier: 1) items = [ item, TypeUnderTest( - metadata: TypeUnderTest.Metadata(categoryIdentifier: 2), identifier: "gin-123", name: "Boxer Gin", barcode: .UPCA(5, 10, 15, 20) ), TypeUnderTest( - metadata: TypeUnderTest.Metadata(categoryIdentifier: 3), identifier: "rum-123", name: "Mount Gay Rum", barcode: .UPCA(12, 24, 39, 48) ), TypeUnderTest( - metadata: TypeUnderTest.Metadata(categoryIdentifier: 2), identifier: "gin-234", name: "Monkey 47", barcode: .UPCA(31, 62, 93, 124) ) ] + metadatas = [ + metadata, + MetadataTypeUnderTest(categoryIdentifier: 2), + MetadataTypeUnderTest(categoryIdentifier: 3), + MetadataTypeUnderTest(categoryIdentifier: 4) + ] } func configureForReadingSingle() { readTransaction.object = item.encoded - readTransaction.metadata = item.metadata?.encoded + readTransaction.metadata = metadata?.encoded } func configureForReadingMultiple() { readTransaction.objects = items.encoded - readTransaction.metadatas = items.map { $0.metadata?.encoded } + readTransaction.metadatas = metadatas.map { $0?.encoded } readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: TypeUnderTest) { - XCTAssertEqual(result.identifier, item.identifier) + func checkTransactionDidWriteItem(result: (TypeUnderTest, MetadataTypeUnderTest?)) { + XCTAssertEqual(result.0.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(TypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].1)!, item) - XCTAssertEqual(TypeUnderTest.MetadataType.decode(writeTransaction.didWriteAtIndexes[0].2), item.metadata) + XCTAssertEqual(MetadataTypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].2), metadata) } - func checkTransactionDidWriteItems(result: [TypeUnderTest]) { + func checkTransactionDidWriteItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) - XCTAssertEqual(Set(result), Set(items)) + XCTAssertEqual(Set(result.map({$0.0})), Set(items)) } - func checkTransactionDidReadItem(result: TypeUnderTest?) -> Bool { + func checkTransactionDidReadItem(result: (TypeUnderTest, MetadataTypeUnderTest?)?) -> Bool { XCTAssertEqual(readTransaction.didReadAtIndex, index) guard let result = result else { return false } XCTAssertEqual(readTransaction.didReadMetadataAtIndex, index) - XCTAssertEqual(result.identifier, item.identifier) - XCTAssertEqual(result.metadata, item.metadata) + XCTAssertEqual(result.0.identifier, item.identifier) + XCTAssertEqual(result.1, metadata) return true } - func checkTransactionDidReadItems(result: [TypeUnderTest]) -> Bool { + func checkTransactionDidReadItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) -> Bool { if result.isEmpty { return false } @@ -148,17 +156,17 @@ class ValueWithValueMetadataTests: XCTestCase { return true } - func checkTransactionDidReadMetadataItem(result: TypeUnderTest.MetadataType?) -> Bool { + func checkTransactionDidReadMetadataItem(result: MetadataTypeUnderTest?) -> Bool { XCTAssertNil(readTransaction.didReadAtIndex) guard let result = result else { return false } XCTAssertEqual(readTransaction.didReadMetadataAtIndex, index) - XCTAssertEqual(result, item.metadata) + XCTAssertEqual(result, metadata) return true } - func checkTransactionDidReadMetadataItems(result: [TypeUnderTest.MetadataType]) -> Bool { + func checkTransactionDidReadMetadataItems(result: [MetadataTypeUnderTest]) -> Bool { XCTAssertTrue(readTransaction.didReadAtIndexes.isEmpty) if result.isEmpty { return false @@ -183,7 +191,7 @@ class ValueWithValueMetadataTests: XCTestCase { class Base_ValueWithValueMetadataTests: ValueWithValueMetadataTests { func test__metadata_is_not_nil() { - XCTAssertNotNil(item.metadata) + XCTAssertNotNil(metadata) } } @@ -193,116 +201,116 @@ class Functional_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests { func test__transaction__read_at_index_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readAtIndex(index))) + XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readWithMetadataAtIndex(index))) } func test__transaction__read_at_index_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readAtIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readWithMetadataAtIndex(index))) } func test__transaction__read_at_indexes_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readAtIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataAtIndexes(indexes))) } func test__transaction__read_at_indexes_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readAtIndexes(Set(indexes)))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataAtIndexes(Set(indexes)))) } func test__transaction__read_at_indexes_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readAtIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readWithMetadataAtIndexes(indexes))) } func test__transaction__read_by_key_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readByKey(key))) + XCTAssertTrue(checkTransactionDidReadItem(readTransaction.readWithMetadataByKey(key))) } func test__transaction__read_by_key_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readByKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(readTransaction.readWithMetadataByKey(key))) } func test__transaction__read_by_keys_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readByKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataByKeys(keys))) } func test__transaction__read_by_keys_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readByKeys(Set(keys)))) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataByKeys(Set(keys)))) } func test__transaction__read_by_keys_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readByKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(readTransaction.readWithMetadataByKeys(keys))) } func test__transaction__read_all_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readAll())) + XCTAssertTrue(checkTransactionDidReadItems(readTransaction.readWithMetadataAll())) } // Functional API - ConnectionType - Reading func test__connection__read_at_index_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.readAtIndex(index))) + XCTAssertTrue(checkTransactionDidReadItem(connection.readWithMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_index_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.readAtIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(connection.readWithMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_indexes_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readAtIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_indexes_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readAtIndexes(Set(indexes)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataAtIndexes(Set(indexes)))) XCTAssertTrue(connection.didRead) } func test__connection__read_at_indexes_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.readAtIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(connection.readWithMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_key_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.readByKey(key))) + XCTAssertTrue(checkTransactionDidReadItem(connection.readWithMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_key_without_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.readByKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(connection.readWithMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_keys_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readByKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_keys_with_data_2() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readByKeys(Set(keys)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataByKeys(Set(keys)))) XCTAssertTrue(connection.didRead) } func test__connection__read_by_keys_without_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.readByKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(connection.readWithMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__connection__read_all_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.readAll())) + XCTAssertTrue(checkTransactionDidReadItems(connection.readWithMetadataAll())) XCTAssertTrue(connection.didRead) } } @@ -353,38 +361,29 @@ class Functional_Read_Metadata_ValueWithValueMetadataTests: ValueWithValueMetada class Functional_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests { func test__transaction__write_item() { - checkTransactionDidWriteItem(writeTransaction.write(item)) + checkTransactionDidWriteItem(writeTransaction.writeWithMetadata((item, metadata))) } func test__transaction__write_items() { - checkTransactionDidWriteItems(writeTransaction.write(items)) - } - - func test__transaction__write_items_2() { - checkTransactionDidWriteItems(writeTransaction.write(Set(items))) + checkTransactionDidWriteItems(writeTransaction.writeWithMetadata(zipToWrite(items, metadatas))) } // MARK: - Functional API - Connection - Writing func test__connection__write_item() { - checkTransactionDidWriteItem(connection.write(item)) + checkTransactionDidWriteItem(connection.writeWithMetadata((item, metadata))) XCTAssertTrue(connection.didWrite) } func test__connection__write_items() { - checkTransactionDidWriteItems(connection.write(items)) - XCTAssertTrue(connection.didWrite) - } - - func test__connection__write_items_2() { - checkTransactionDidWriteItems(connection.write(Set(items))) + checkTransactionDidWriteItems(connection.writeWithMetadata(zipToWrite(items, metadatas))) XCTAssertTrue(connection.didWrite) } func test__connection__async_write_item() { - var result: TypeUnderTest! + var result: (TypeUnderTest, MetadataTypeUnderTest?)! let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWrite(item) { tmp in + connection.asyncWriteWithMetadata((item, metadata)) { tmp in result = tmp expectation.fulfill() } @@ -394,9 +393,9 @@ class Functional_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests } func test__connection__async_write_items() { - var result: [TypeUnderTest] = [] + var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWrite(items) { received in + connection.asyncWriteWithMetadata(zipToWrite(items, metadatas)) { received in result = received expectation.fulfill() } @@ -463,45 +462,45 @@ class Curried_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests { func test__curried__read_at_index_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readAtIndex(index)))) + XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataAtIndex(index)))) XCTAssertTrue(connection.didRead) } func test__curried__read_at_index_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readAtIndex(index)))) + XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataAtIndex(index)))) XCTAssertTrue(connection.didRead) } func test__curried__read_at_indexes_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readAtIndexes(indexes)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataAtIndexes(indexes)))) XCTAssertTrue(connection.didRead) } func test__curried__read_at_indexes_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readAtIndexes(indexes)))) + XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataAtIndexes(indexes)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_key_with_data() { configureForReadingSingle() - XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readByKey(key)))) + XCTAssertTrue(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataByKey(key)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_key_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readByKey(key)))) + XCTAssertFalse(checkTransactionDidReadItem(connection.read(TypeUnderTest.readWithMetadataByKey(key)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_keys_with_data() { configureForReadingMultiple() - XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readByKeys(keys)))) + XCTAssertTrue(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataByKeys(keys)))) XCTAssertTrue(connection.didRead) } func test__curried__read_by_keys_with_no_data() { - XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readByKeys(keys)))) + XCTAssertFalse(checkTransactionDidReadItems(connection.read(TypeUnderTest.readWithMetadataByKeys(keys)))) XCTAssertTrue(connection.didRead) } } @@ -509,7 +508,7 @@ class Curried_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests { class Curried_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests { func test__curried__write() { - checkTransactionDidWriteItem(connection.write(item.write())) + checkTransactionDidWriteItem(connection.write(item.writeWithMetadata(metadata))) XCTAssertTrue(connection.didWrite) } } @@ -521,69 +520,69 @@ class Persistable_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests func test__reader__in_transaction_at_index() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, atIndex: index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, atIndex: index))) } func test__reader__in_transaction_at_index_2() { configureForReadingSingle() reader = Read(readTransaction) - let atIndex = reader.inTransactionAtIndex(readTransaction) + let atIndex: YapDB.Index -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionAtIndex(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(atIndex(index))) } func test__reader__at_index_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction = reader.atIndexInTransaction(index) + let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataAtIndexInTransaction(index) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } func test__reader__at_indexes_in_transaction_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.atIndexesInTransaction(indexes)(readTransaction))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAtIndexesInTransaction(indexes)(readTransaction))) } func test__reader__at_indexes_in_transaction_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.atIndexesInTransaction(indexes)(readTransaction))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAtIndexesInTransaction(indexes)(readTransaction))) } func test__reader__in_transaction_by_key() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, byKey: key))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, byKey: key))) } func test__reader__in_transaction_by_key_2() { configureForReadingSingle() reader = Read(readTransaction) - let byKey = reader.inTransactionByKey(readTransaction) + let byKey: String -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionByKey(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(byKey(key))) } func test__reader__by_key_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction = reader.byKeyInTransaction(key) + let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataByKeyInTransaction(key) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } func test__reader__by_keys_in_transaction_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeysInTransaction(keys)(readTransaction))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeysInTransaction(keys)(readTransaction))) } func test__reader__by_keys_in_transaction_with_items_with_keys() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeysInTransaction()(readTransaction))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeysInTransaction()(readTransaction))) } func test__reader__by_keys_in_transaction_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.byKeysInTransaction(keys)(readTransaction))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataByKeysInTransaction(keys)(readTransaction))) } // Reading - With Transaction @@ -591,66 +590,66 @@ class Persistable_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests func test__reader_with_transaction__at_index_with_item() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, atIndex: index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, atIndex: index))) } func test__reader_with_transaction__at_index_with_no_item() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItem(reader.atIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataAtIndex(index))) } func test__reader_with_transaction__at_indexes_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) } func test__reader_with_transaction__at_indexes_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) } func test__reader_with_transaction__by_key_with_item() { configureForReadingSingle() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItem(reader.inTransaction(readTransaction, atIndex: index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataInTransaction(readTransaction, atIndex: index))) } func test__reader_with_transaction__by_key_with_no_item() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItem(reader.byKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataByKey(key))) } func test__reader_with_transaction__by_keys_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) } func test__reader_with_transaction__by_keys_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) } func test__reader_with_transaction__all_with_items() { configureForReadingMultiple() reader = Read(readTransaction) - XCTAssertTrue(checkTransactionDidReadItems(reader.all())) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } func test__reader_with_transaction__all_with_no_items() { reader = Read(readTransaction) - XCTAssertFalse(checkTransactionDidReadItems(reader.all())) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } func test__reader_with_transaction__filter() { configureForReadingSingle() reader = Read(readTransaction) - let (items, missing) = reader.filterExisting(keys) + let (items, missing): ([(TypeUnderTest, MetadataTypeUnderTest?)], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.identifier }, items.prefixUpTo(1).map { $0.identifier }) + XCTAssertEqual(items.map { $0.0.identifier }, items.prefixUpTo(1).map { $0.0.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -659,66 +658,66 @@ class Persistable_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests func test__reader_with_connection__at_index_with_item() { configureForReadingSingle() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItem(reader.atIndex(index))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__at_index_with_no_item() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItem(reader.atIndex(index))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataAtIndex(index))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__at_indexes_with_items() { configureForReadingMultiple() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__at_indexes_with_no_items() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItems(reader.atIndexes(indexes))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAtIndexes(indexes))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_key_with_item() { configureForReadingSingle() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItem(reader.byKey(key))) + XCTAssertTrue(checkTransactionDidReadItem(reader.withMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_key_with_no_item() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItem(reader.byKey(key))) + XCTAssertFalse(checkTransactionDidReadItem(reader.withMetadataByKey(key))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_keys_with_items() { configureForReadingMultiple() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__by_keys_with_no_items() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItems(reader.byKeys(keys))) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataByKeys(keys))) XCTAssertTrue(connection.didRead) } func test__reader_with_connection__all_with_items() { configureForReadingMultiple() reader = Read(connection) - XCTAssertTrue(checkTransactionDidReadItems(reader.all())) + XCTAssertTrue(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } func test__reader_with_connection__all_with_no_items() { reader = Read(connection) - XCTAssertFalse(checkTransactionDidReadItems(reader.all())) + XCTAssertFalse(checkTransactionDidReadItems(reader.withMetadataAll())) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didKeysInCollection, TypeUnderTest.collection) } @@ -789,19 +788,19 @@ class Persistable_Read_Metadata_ValueWithValueMetadataTests: ValueWithValueMetad class Persistable_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests { func test__item_persistable__write_using_transaction() { - checkTransactionDidWriteItem(item.write(writeTransaction)) + checkTransactionDidWriteItem(item.writeWithMetadata(writeTransaction, metadata: metadata)) } func test__item_persistable__write_using_connection() { - checkTransactionDidWriteItem(item.write(connection)) + checkTransactionDidWriteItem(item.writeWithMetadata(connection, metadata: metadata)) XCTAssertTrue(connection.didWrite) } func test__item_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: TypeUnderTest! = nil + var result: (TypeUnderTest, MetadataTypeUnderTest?)! = nil - item.asyncWrite(connection) { tmp in + item.asyncWriteWithMetadata(connection, metadata: metadata) { tmp in result = tmp expectation.fulfill() } @@ -813,7 +812,7 @@ class Persistable_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests func test__item_persistable__write_using_opertion() { let expectation = expectationWithDescription("Test: \(#function)") - let operation = item.writeOperation(connection) + let operation = item.writeWithMetadataOperation(connection, metadata: metadata) operation.completionBlock = { expectation.fulfill() } @@ -823,24 +822,24 @@ class Persistable_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(TypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].1)!, item) - XCTAssertEqual(TypeUnderTest.MetadataType.decode(writeTransaction.didWriteAtIndexes[0].2), item.metadata) + XCTAssertEqual(MetadataTypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].2), metadata) XCTAssertTrue(connection.didWrite) } func test__items_persistable__write_using_transaction() { - checkTransactionDidWriteItems(items.write(writeTransaction)) + checkTransactionDidWriteItems(items.writeWithMetadata(writeTransaction, metadata: metadatas)) } func test__items_persistable__write_using_connection() { - checkTransactionDidWriteItems(items.write(connection)) + checkTransactionDidWriteItems(items.writeWithMetadata(connection, metadata: metadatas)) XCTAssertTrue(connection.didWrite) } func test__items_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: [TypeUnderTest] = [] - - items.asyncWrite(connection) { tmp in + var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] + + items.asyncWriteWithMetadata(connection, metadata: metadatas) { tmp in result = tmp expectation.fulfill() } @@ -852,7 +851,7 @@ class Persistable_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests func test__items_persistable__write_using_opertion() { let expectation = expectationWithDescription("Test: \(#function)") - let operation = items.writeOperation(connection) + let operation = items.writeWithMetadataOperation(connection, metadata: metadatas) operation.completionBlock = { expectation.fulfill() } diff --git a/Tests/Shared/YapDatabaseExtensionsTests.swift b/Tests/Shared/YapDatabaseExtensionsTests.swift index 90dfae7..d3b475c 100644 --- a/Tests/Shared/YapDatabaseExtensionsTests.swift +++ b/Tests/Shared/YapDatabaseExtensionsTests.swift @@ -106,19 +106,18 @@ class YapDatabaseReadWriteTransactionTests: ReadWriteBaseTests { } let written = Employee.read(db).atIndex(index) XCTAssertNotNil(written) - XCTAssertNil(written!.metadata) XCTAssertEqual(written!.identifier, item.identifier) } func test__write_at_index_with_metadata() { let db = YapDB.testDatabase() db.makeNewConnection().readWriteWithBlock { transaction in - transaction.writeAtIndex(self.index, object: self.item, metadata: self.item.metadata) + transaction.writeAtIndex(self.index, object: self.item, metadata: self.metadata) } - let written = Employee.read(db).atIndex(index) + let written: (Employee, NSDate?)? = Employee.read(db).withMetadataAtIndex(index) XCTAssertNotNil(written) - XCTAssertNotNil(written!.metadata) - XCTAssertEqual(written!.identifier, item.identifier) + XCTAssertNotNil(written!.1) + XCTAssertEqual(written!.0.identifier, item.identifier) } func test__remove_at_indexes() { @@ -172,7 +171,7 @@ class YapDatabaseConnectionTests: ReadWriteBaseTests { var written: Employee? = .None db.makeNewConnection().asyncWrite({ transaction -> Employee? in - transaction.writeAtIndex(self.index, object: self.item, metadata: self.item.metadata) + transaction.writeAtIndex(self.index, object: self.item, metadata: self.metadata) return self.item }, queue: dispatchQueue) { (result: Employee?) in written = result @@ -206,10 +205,12 @@ class YapDatabaseConnectionTests: ReadWriteBaseTests { class ValueCodingTests: XCTestCase { var item: Product! + var metadata: Product.Metadata! var index: YapDB.Index! var key: String! var items: [Product]! + var metadatas: [Product.Metadata?]! var indexes: [YapDB.Index]! var keys: [String]! @@ -225,9 +226,11 @@ class ValueCodingTests: XCTestCase { override func tearDown() { item = nil + metadata = nil index = nil key = nil items = nil + metadatas = nil indexes = nil keys = nil super.tearDown() @@ -235,32 +238,35 @@ class ValueCodingTests: XCTestCase { func createPersistables() { item = Product( - metadata: Product.Metadata(categoryIdentifier: 1), identifier: "vodka-123", name: "Belvidere", barcode: .UPCA(1, 2, 3, 4) ) + metadata = Product.Metadata(categoryIdentifier: 1) items = [ item, Product( - metadata: Product.Metadata(categoryIdentifier: 2), identifier: "gin-123", name: "Boxer Gin", barcode: .UPCA(5, 10, 15, 20) ), Product( - metadata: Product.Metadata(categoryIdentifier: 3), identifier: "rum-123", name: "Mount Gay Rum", barcode: .UPCA(12, 24, 39, 48) ), Product( - metadata: Product.Metadata(categoryIdentifier: 2), identifier: "gin-234", name: "Monkey 47", barcode: .UPCA(31, 62, 93, 124) ) ] + metadatas = [ + metadata, + Product.Metadata(categoryIdentifier: 2), + Product.Metadata(categoryIdentifier: 3), + Product.Metadata(categoryIdentifier: 2) + ] } func test__index_is_hashable() { From eb22d8e94bef34b95bc29096496f79b72b075f01 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 15 Sep 2016 21:31:33 -0700 Subject: [PATCH 13/54] use new YapItem struct instead of tuples, replace zipToWrite with an extension on SequenceType --- .../ObjectWithObjectMetadataTests.swift | 48 +++++------ .../Shared/ObjectWithValueMetadataTests.swift | 48 +++++------ Tests/Shared/ReadWriteTests.swift | 2 +- .../Shared/ValueWithObjectMetadataTests.swift | 48 +++++------ .../Shared/ValueWithValueMetadataTests.swift | 48 +++++------ Tests/Shared/YapDatabaseExtensionsTests.swift | 6 +- .../Curried_ObjectWithObjectMetadata.swift | 12 +-- .../Curried_ObjectWithValueMetadata.swift | 12 +-- .../Curried_ValueWithObjectMetadata.swift | 12 +-- .../Curried_ValueWithValueMetadata.swift | 12 +-- .../Functional_ObjectWithObjectMetadata.swift | 42 +++++----- .../Functional_ObjectWithValueMetadata.swift | 42 +++++----- .../Functional_ValueWIthObjectMetadata.swift | 42 +++++----- .../Functional_ValueWIthValueMetadata.swift | 42 +++++----- ...Persistable_ObjectWithObjectMetadata.swift | 77 ++++++++++-------- .../Persistable_ObjectWithValueMetadata.swift | 79 +++++++++++-------- .../Persistable_ValueWithObjectMetadata.swift | 77 ++++++++++-------- .../Persistable_ValueWithValueMetadata.swift | 79 +++++++++++-------- .../Shared/YapDatabaseExtensions.swift | 34 +++++--- 19 files changed, 420 insertions(+), 342 deletions(-) diff --git a/Tests/Shared/ObjectWithObjectMetadataTests.swift b/Tests/Shared/ObjectWithObjectMetadataTests.swift index a91ec71..ea690a2 100644 --- a/Tests/Shared/ObjectWithObjectMetadataTests.swift +++ b/Tests/Shared/ObjectWithObjectMetadataTests.swift @@ -100,34 +100,34 @@ class ObjectWithObjectMetadataTests: XCTestCase { readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: (TypeUnderTest, MetadataTypeUnderTest?)) { - XCTAssertEqual(result.0.identifier, item.identifier) + func checkTransactionDidWriteItem(result: YapItem) { + XCTAssertEqual(result.value.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSDate, metadata) } - func checkTransactionDidWriteItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) { + func checkTransactionDidWriteItems(result: [YapItem]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) - XCTAssertEqual(Set(result.map({$0.0})), Set(items)) + XCTAssertEqual(Set(result.map({$0.value})), Set(items)) } - func checkTransactionDidReadItem(result: (TypeUnderTest, MetadataTypeUnderTest?)?) -> Bool { + func checkTransactionDidReadItem(result: YapItem?) -> Bool { guard let result = result else { return false } XCTAssertEqual(readTransaction.didReadAtIndex, index) - XCTAssertEqual(result.0.identifier, item.identifier) + XCTAssertEqual(result.value.identifier, item.identifier) XCTAssertEqual(readTransaction.didReadMetadataAtIndex, index) - XCTAssertEqual(result.1, metadata) + XCTAssertEqual(result.metadata, metadata) return true } - func checkTransactionDidReadItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) -> Bool { + func checkTransactionDidReadItems(result: [YapItem]) -> Bool { if result.isEmpty { return false } @@ -278,29 +278,29 @@ class Functional_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTes class Functional_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTests { func test__transaction__write_item() { - checkTransactionDidWriteItem(writeTransaction.writeWithMetadata((item, metadata))) + checkTransactionDidWriteItem(writeTransaction.writeWithMetadata(YapItem(item, metadata))) } func test__transaction__write_items() { - checkTransactionDidWriteItems(writeTransaction.writeWithMetadata(zipToWrite(items, metadatas))) + checkTransactionDidWriteItems(writeTransaction.writeWithMetadata(items.yapItems(with: metadatas))) } // MARK: - Functional API - Connection - Writing func test__connection__write_item() { - checkTransactionDidWriteItem(connection.writeWithMetadata((item, metadata))) + checkTransactionDidWriteItem(connection.writeWithMetadata(YapItem(item, metadata))) XCTAssertTrue(connection.didWrite) } func test__connection__write_items() { - checkTransactionDidWriteItems(connection.writeWithMetadata(zipToWrite(items, metadatas))) + checkTransactionDidWriteItems(connection.writeWithMetadata(items.yapItems(with: metadatas))) XCTAssertTrue(connection.didWrite) } func test__connection__async_write_item() { - var result: (TypeUnderTest, MetadataTypeUnderTest?)! + var result: YapItem! let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWriteWithMetadata((item, metadata)) { tmp in + connection.asyncWriteWithMetadata(YapItem(item, metadata)) { tmp in result = tmp expectation.fulfill() } @@ -310,9 +310,9 @@ class Functional_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe } func test__connection__async_write_items() { - var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] + var result: [YapItem] = [] let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWriteWithMetadata(zipToWrite(items, metadatas)) { received in + connection.asyncWriteWithMetadata(items.yapItems(with: metadatas)) { received in result = received expectation.fulfill() } @@ -443,14 +443,14 @@ class Persistable_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe func test__reader__in_transaction_at_index_2() { configureForReadingSingle() reader = Read(readTransaction) - let atIndex: YapDB.Index -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionAtIndex(readTransaction) + let atIndex: YapDB.Index -> YapItem? = reader.withMetadataInTransactionAtIndex(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(atIndex(index))) } func test__reader__at_index_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataAtIndexInTransaction(index) + let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataAtIndexInTransaction(index) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -474,14 +474,14 @@ class Persistable_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe func test__reader__in_transaction_by_key_2() { configureForReadingSingle() reader = Read(readTransaction) - let byKey: String -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionByKey(readTransaction) + let byKey: String -> YapItem? = reader.withMetadataInTransactionByKey(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(byKey(key))) } func test__reader__by_key_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataByKeyInTransaction(key) + let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataByKeyInTransaction(key) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -564,9 +564,9 @@ class Persistable_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe func test__reader_with_transaction__filter() { configureForReadingSingle() reader = Read(readTransaction) - let (items, missing): ([(TypeUnderTest, MetadataTypeUnderTest?)], [String]) = reader.withMetadataFilterExisting(keys) + let (items, missing): ([YapItem], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.0.identifier }, items.prefixUpTo(1).map { $0.0.identifier }) + XCTAssertEqual(items.map { $0.value.identifier }, items.prefixUpTo(1).map { $0.value.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -664,7 +664,7 @@ class Persistable_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataT func test__item_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: (TypeUnderTest, MetadataTypeUnderTest?)! = nil + var result: YapItem! = nil item.asyncWriteWithMetadata(connection, metadata: metadata) { tmp in result = tmp @@ -703,7 +703,7 @@ class Persistable_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataT func test__items_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] + var result: [YapItem] = [] items.asyncWriteWithMetadata(connection, metadata: metadatas) { tmp in result = tmp diff --git a/Tests/Shared/ObjectWithValueMetadataTests.swift b/Tests/Shared/ObjectWithValueMetadataTests.swift index 919eec4..7fb12a4 100644 --- a/Tests/Shared/ObjectWithValueMetadataTests.swift +++ b/Tests/Shared/ObjectWithValueMetadataTests.swift @@ -104,34 +104,34 @@ class ObjectWithValueMetadataTests: XCTestCase { readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: (TypeUnderTest, MetadataTypeUnderTest?)) { - XCTAssertEqual(result.0.identifier, item.identifier) + func checkTransactionDidWriteItem(result: YapItem) { + XCTAssertEqual(result.value.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) XCTAssertEqual(MetadataTypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].2), metadata) } - func checkTransactionDidWriteItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) { + func checkTransactionDidWriteItems(result: [YapItem]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) - XCTAssertEqual(Set(result.map({$0.0})), Set(items)) + XCTAssertEqual(Set(result.map({$0.value})), Set(items)) } - func checkTransactionDidReadItem(result: (TypeUnderTest, MetadataTypeUnderTest?)?) -> Bool { + func checkTransactionDidReadItem(result: YapItem?) -> Bool { guard let result = result else { return false } XCTAssertEqual(readTransaction.didReadAtIndex, index) - XCTAssertEqual(result.0.identifier, item.identifier) + XCTAssertEqual(result.value.identifier, item.identifier) XCTAssertEqual(readTransaction.didReadMetadataAtIndex, index) - XCTAssertEqual(result.1, metadata) + XCTAssertEqual(result.metadata, metadata) return true } - func checkTransactionDidReadItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) -> Bool { + func checkTransactionDidReadItems(result: [YapItem]) -> Bool { if result.isEmpty { return false } @@ -282,29 +282,29 @@ class Functional_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTests class Functional_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTests { func test__transaction__write_item() { - checkTransactionDidWriteItem(writeTransaction.writeWithMetadata((item, metadata))) + checkTransactionDidWriteItem(writeTransaction.writeWithMetadata(YapItem(item, metadata))) } func test__transaction__write_items() { - checkTransactionDidWriteItems(writeTransaction.writeWithMetadata(zipToWrite(items, metadatas))) + checkTransactionDidWriteItems(writeTransaction.writeWithMetadata(items.yapItems(with: metadatas))) } // MARK: - Functional API - Connection - Writing func test__connection__write_item() { - checkTransactionDidWriteItem(connection.writeWithMetadata((item, metadata))) + checkTransactionDidWriteItem(connection.writeWithMetadata(YapItem(item, metadata))) XCTAssertTrue(connection.didWrite) } func test__connection__write_items() { - checkTransactionDidWriteItems(connection.writeWithMetadata(zipToWrite(items, metadatas))) + checkTransactionDidWriteItems(connection.writeWithMetadata(items.yapItems(with: metadatas))) XCTAssertTrue(connection.didWrite) } func test__connection__async_write_item() { - var result: (TypeUnderTest, MetadataTypeUnderTest?)! + var result: YapItem! let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWriteWithMetadata((item, metadata)) { tmp in + connection.asyncWriteWithMetadata(YapItem(item, metadata)) { tmp in result = tmp expectation.fulfill() } @@ -314,9 +314,9 @@ class Functional_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest } func test__connection__async_write_items() { - var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] + var result: [YapItem] = [] let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWriteWithMetadata(zipToWrite(items, metadatas)) { received in + connection.asyncWriteWithMetadata(items.yapItems(with: metadatas)) { received in result = received expectation.fulfill() } @@ -447,14 +447,14 @@ class Persistable_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest func test__reader__in_transaction_at_index_2() { configureForReadingSingle() reader = Read(readTransaction) - let atIndex: YapDB.Index -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionAtIndex(readTransaction) + let atIndex: YapDB.Index -> YapItem? = reader.withMetadataInTransactionAtIndex(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(atIndex(index))) } func test__reader__at_index_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataAtIndexInTransaction(index) + let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataAtIndexInTransaction(index) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -478,14 +478,14 @@ class Persistable_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest func test__reader__in_transaction_by_key_2() { configureForReadingSingle() reader = Read(readTransaction) - let byKey: String -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionByKey(readTransaction) + let byKey: String -> YapItem? = reader.withMetadataInTransactionByKey(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(byKey(key))) } func test__reader__by_key_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataByKeyInTransaction(key) + let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataByKeyInTransaction(key) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -568,9 +568,9 @@ class Persistable_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest func test__reader_with_transaction__filter() { configureForReadingSingle() reader = Read(readTransaction) - let (items, missing): ([(TypeUnderTest, MetadataTypeUnderTest?)], [String]) = reader.withMetadataFilterExisting(keys) + let (items, missing): ([YapItem], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.0.identifier }, items.prefixUpTo(1).map { $0.0.identifier }) + XCTAssertEqual(items.map { $0.value.identifier }, items.prefixUpTo(1).map { $0.value.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -668,7 +668,7 @@ class Persistable_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTes func test__item_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: (TypeUnderTest, MetadataTypeUnderTest?)! = nil + var result: YapItem! = nil item.asyncWriteWithMetadata(connection, metadata: metadata) { tmp in result = tmp @@ -707,7 +707,7 @@ class Persistable_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTes func test__items_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] + var result: [YapItem] = [] items.asyncWriteWithMetadata(connection, metadata: metadatas) { tmp in result = tmp diff --git a/Tests/Shared/ReadWriteTests.swift b/Tests/Shared/ReadWriteTests.swift index f1c14c3..f526e8d 100644 --- a/Tests/Shared/ReadWriteTests.swift +++ b/Tests/Shared/ReadWriteTests.swift @@ -59,7 +59,7 @@ class ReadWriteBaseTests: XCTestCase { } func writeItemsToDatabase(db: YapDatabase) { - db.makeNewConnection().writeWithMetadata(zipToWrite(items, metadatas)) + db.makeNewConnection().writeWithMetadata(items.yapItems(with: metadatas)) } } diff --git a/Tests/Shared/ValueWithObjectMetadataTests.swift b/Tests/Shared/ValueWithObjectMetadataTests.swift index 80e9b14..b954985 100644 --- a/Tests/Shared/ValueWithObjectMetadataTests.swift +++ b/Tests/Shared/ValueWithObjectMetadataTests.swift @@ -122,34 +122,34 @@ class ValueWithObjectMetadataTests: XCTestCase { readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: (TypeUnderTest, MetadataTypeUnderTest?)) { - XCTAssertEqual(result.0.identifier, item.identifier) + func checkTransactionDidWriteItem(result: YapItem) { + XCTAssertEqual(result.value.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(TypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].1)!, item) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSNumber, metadata) } - func checkTransactionDidWriteItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) { + func checkTransactionDidWriteItems(result: [YapItem]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) - XCTAssertEqual(Set(result.map({$0.0})), Set(items)) + XCTAssertEqual(Set(result.map({$0.value})), Set(items)) } - func checkTransactionDidReadItem(result: (TypeUnderTest, MetadataTypeUnderTest?)?) -> Bool { + func checkTransactionDidReadItem(result: YapItem?) -> Bool { XCTAssertEqual(readTransaction.didReadAtIndex, index) guard let result = result else { return false } XCTAssertEqual(readTransaction.didReadMetadataAtIndex, index) - XCTAssertEqual(result.0.identifier, item.identifier) - XCTAssertEqual(result.1, metadata) + XCTAssertEqual(result.value.identifier, item.identifier) + XCTAssertEqual(result.metadata, metadata) return true } - func checkTransactionDidReadItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) -> Bool { + func checkTransactionDidReadItems(result: [YapItem]) -> Bool { if result.isEmpty { return false } @@ -364,29 +364,29 @@ class Functional_Read_Metadata_ValueWithObjectMetadataTests: ValueWithObjectMeta class Functional_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTests { func test__transaction__write_item() { - checkTransactionDidWriteItem(writeTransaction.writeWithMetadata((item, metadata))) + checkTransactionDidWriteItem(writeTransaction.writeWithMetadata(YapItem(item, metadata))) } func test__transaction__write_items() { - checkTransactionDidWriteItems(writeTransaction.writeWithMetadata(zipToWrite(items, metadatas))) + checkTransactionDidWriteItems(writeTransaction.writeWithMetadata(items.yapItems(with: metadatas))) } // MARK: - Functional API - Connection - Writing func test__connection__write_item() { - checkTransactionDidWriteItem(connection.writeWithMetadata((item, metadata))) + checkTransactionDidWriteItem(connection.writeWithMetadata(YapItem(item, metadata))) XCTAssertTrue(connection.didWrite) } func test__connection__write_items() { - checkTransactionDidWriteItems(connection.writeWithMetadata(zipToWrite(items, metadatas))) + checkTransactionDidWriteItems(connection.writeWithMetadata(items.yapItems(with: metadatas))) XCTAssertTrue(connection.didWrite) } func test__connection__async_write_item() { - var result: (TypeUnderTest, MetadataTypeUnderTest?)! + var result: YapItem! let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWriteWithMetadata((item, metadata)) { tmp in + connection.asyncWriteWithMetadata(YapItem(item, metadata)) { tmp in result = tmp expectation.fulfill() } @@ -396,9 +396,9 @@ class Functional_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest } func test__connection__async_write_items() { - var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] + var result: [YapItem] = [] let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWriteWithMetadata(zipToWrite(items, metadatas)) { received in + connection.asyncWriteWithMetadata(items.yapItems(with: metadatas)) { received in result = received expectation.fulfill() } @@ -529,14 +529,14 @@ class Persistable_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest func test__reader__in_transaction_at_index_2() { configureForReadingSingle() reader = Read(readTransaction) - let atIndex: YapDB.Index -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionAtIndex(readTransaction) + let atIndex: YapDB.Index -> YapItem? = reader.withMetadataInTransactionAtIndex(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(atIndex(index))) } func test__reader__at_index_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataAtIndexInTransaction(index) + let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataAtIndexInTransaction(index) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -560,14 +560,14 @@ class Persistable_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest func test__reader__in_transaction_by_key_2() { configureForReadingSingle() reader = Read(readTransaction) - let byKey: String -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionByKey(readTransaction) + let byKey: String -> YapItem? = reader.withMetadataInTransactionByKey(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(byKey(key))) } func test__reader__by_key_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataByKeyInTransaction(key) + let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataByKeyInTransaction(key) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -650,9 +650,9 @@ class Persistable_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest func test__reader_with_transaction__filter() { configureForReadingSingle() reader = Read(readTransaction) - let (items, missing): ([(TypeUnderTest, MetadataTypeUnderTest?)], [String]) = reader.withMetadataFilterExisting(keys) + let (items, missing): ([YapItem], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.0.identifier }, items.prefixUpTo(1).map { $0.0.identifier }) + XCTAssertEqual(items.map { $0.value.identifier }, items.prefixUpTo(1).map { $0.value.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -801,7 +801,7 @@ class Persistable_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTes func test__item_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: (TypeUnderTest, MetadataTypeUnderTest?)! = nil + var result: YapItem! = nil item.asyncWriteWithMetadata(connection, metadata: metadata) { tmp in result = tmp @@ -840,7 +840,7 @@ class Persistable_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTes func test__items_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] + var result: [YapItem] = [] items.asyncWriteWithMetadata(connection, metadata: metadatas) { tmp in result = tmp diff --git a/Tests/Shared/ValueWithValueMetadataTests.swift b/Tests/Shared/ValueWithValueMetadataTests.swift index d6b4fd6..4b1b257 100644 --- a/Tests/Shared/ValueWithValueMetadataTests.swift +++ b/Tests/Shared/ValueWithValueMetadataTests.swift @@ -120,34 +120,34 @@ class ValueWithValueMetadataTests: XCTestCase { readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: (TypeUnderTest, MetadataTypeUnderTest?)) { - XCTAssertEqual(result.0.identifier, item.identifier) + func checkTransactionDidWriteItem(result: YapItem) { + XCTAssertEqual(result.value.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(TypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].1)!, item) XCTAssertEqual(MetadataTypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].2), metadata) } - func checkTransactionDidWriteItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) { + func checkTransactionDidWriteItems(result: [YapItem]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) - XCTAssertEqual(Set(result.map({$0.0})), Set(items)) + XCTAssertEqual(Set(result.map({$0.value})), Set(items)) } - func checkTransactionDidReadItem(result: (TypeUnderTest, MetadataTypeUnderTest?)?) -> Bool { + func checkTransactionDidReadItem(result: YapItem?) -> Bool { XCTAssertEqual(readTransaction.didReadAtIndex, index) guard let result = result else { return false } XCTAssertEqual(readTransaction.didReadMetadataAtIndex, index) - XCTAssertEqual(result.0.identifier, item.identifier) - XCTAssertEqual(result.1, metadata) + XCTAssertEqual(result.value.identifier, item.identifier) + XCTAssertEqual(result.metadata, metadata) return true } - func checkTransactionDidReadItems(result: [(TypeUnderTest, MetadataTypeUnderTest?)]) -> Bool { + func checkTransactionDidReadItems(result: [YapItem]) -> Bool { if result.isEmpty { return false } @@ -361,29 +361,29 @@ class Functional_Read_Metadata_ValueWithValueMetadataTests: ValueWithValueMetada class Functional_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests { func test__transaction__write_item() { - checkTransactionDidWriteItem(writeTransaction.writeWithMetadata((item, metadata))) + checkTransactionDidWriteItem(writeTransaction.writeWithMetadata(YapItem(item, metadata))) } func test__transaction__write_items() { - checkTransactionDidWriteItems(writeTransaction.writeWithMetadata(zipToWrite(items, metadatas))) + checkTransactionDidWriteItems(writeTransaction.writeWithMetadata(items.yapItems(with: metadatas))) } // MARK: - Functional API - Connection - Writing func test__connection__write_item() { - checkTransactionDidWriteItem(connection.writeWithMetadata((item, metadata))) + checkTransactionDidWriteItem(connection.writeWithMetadata(YapItem(item, metadata))) XCTAssertTrue(connection.didWrite) } func test__connection__write_items() { - checkTransactionDidWriteItems(connection.writeWithMetadata(zipToWrite(items, metadatas))) + checkTransactionDidWriteItems(connection.writeWithMetadata(items.yapItems(with: metadatas))) XCTAssertTrue(connection.didWrite) } func test__connection__async_write_item() { - var result: (TypeUnderTest, MetadataTypeUnderTest?)! + var result: YapItem! let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWriteWithMetadata((item, metadata)) { tmp in + connection.asyncWriteWithMetadata(YapItem(item, metadata)) { tmp in result = tmp expectation.fulfill() } @@ -393,9 +393,9 @@ class Functional_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests } func test__connection__async_write_items() { - var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] + var result: [YapItem] = [] let expectation = expectationWithDescription("Test: \(#function)") - connection.asyncWriteWithMetadata(zipToWrite(items, metadatas)) { received in + connection.asyncWriteWithMetadata(items.yapItems(with: metadatas)) { received in result = received expectation.fulfill() } @@ -526,14 +526,14 @@ class Persistable_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests func test__reader__in_transaction_at_index_2() { configureForReadingSingle() reader = Read(readTransaction) - let atIndex: YapDB.Index -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionAtIndex(readTransaction) + let atIndex: YapDB.Index -> YapItem? = reader.withMetadataInTransactionAtIndex(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(atIndex(index))) } func test__reader__at_index_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataAtIndexInTransaction(index) + let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataAtIndexInTransaction(index) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -557,14 +557,14 @@ class Persistable_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests func test__reader__in_transaction_by_key_2() { configureForReadingSingle() reader = Read(readTransaction) - let byKey: String -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataInTransactionByKey(readTransaction) + let byKey: String -> YapItem? = reader.withMetadataInTransactionByKey(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(byKey(key))) } func test__reader__by_key_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> (TypeUnderTest, MetadataTypeUnderTest?)? = reader.withMetadataByKeyInTransaction(key) + let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataByKeyInTransaction(key) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -647,9 +647,9 @@ class Persistable_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests func test__reader_with_transaction__filter() { configureForReadingSingle() reader = Read(readTransaction) - let (items, missing): ([(TypeUnderTest, MetadataTypeUnderTest?)], [String]) = reader.withMetadataFilterExisting(keys) + let (items, missing): ([YapItem], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.0.identifier }, items.prefixUpTo(1).map { $0.0.identifier }) + XCTAssertEqual(items.map { $0.value.identifier }, items.prefixUpTo(1).map { $0.value.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -798,7 +798,7 @@ class Persistable_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests func test__item_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: (TypeUnderTest, MetadataTypeUnderTest?)! = nil + var result: YapItem! = nil item.asyncWriteWithMetadata(connection, metadata: metadata) { tmp in result = tmp @@ -837,7 +837,7 @@ class Persistable_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests func test__items_persistable__write_async_using_connection() { let expectation = expectationWithDescription("Test: \(#function)") - var result: [(TypeUnderTest, MetadataTypeUnderTest?)] = [] + var result: [YapItem] = [] items.asyncWriteWithMetadata(connection, metadata: metadatas) { tmp in result = tmp diff --git a/Tests/Shared/YapDatabaseExtensionsTests.swift b/Tests/Shared/YapDatabaseExtensionsTests.swift index d3b475c..b244ca2 100644 --- a/Tests/Shared/YapDatabaseExtensionsTests.swift +++ b/Tests/Shared/YapDatabaseExtensionsTests.swift @@ -114,10 +114,10 @@ class YapDatabaseReadWriteTransactionTests: ReadWriteBaseTests { db.makeNewConnection().readWriteWithBlock { transaction in transaction.writeAtIndex(self.index, object: self.item, metadata: self.metadata) } - let written: (Employee, NSDate?)? = Employee.read(db).withMetadataAtIndex(index) + let written: YapItem? = Employee.read(db).withMetadataAtIndex(index) XCTAssertNotNil(written) - XCTAssertNotNil(written!.1) - XCTAssertEqual(written!.0.identifier, item.identifier) + XCTAssertNotNil(written!.metadata) + XCTAssertEqual(written!.value.identifier, item.identifier) } func test__remove_at_indexes() { diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithObjectMetadata.swift index 333c42e..77587cb 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithObjectMetadata.swift @@ -24,7 +24,7 @@ extension Persistable where public static func readWithMetadataAtIndex< ReadTransaction, Metadata where ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(index: YapDB.Index) -> ReadTransaction -> (Self, Metadata?)? { + Metadata: NSCoding>(index: YapDB.Index) -> ReadTransaction -> YapItem? { return { $0.readWithMetadataAtIndex(index) } } @@ -40,7 +40,7 @@ extension Persistable where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(indexes: Indexes) -> ReadTransaction -> [(Self, Metadata?)] { + Metadata: NSCoding>(indexes: Indexes) -> ReadTransaction -> [YapItem] { return { $0.readWithMetadataAtIndexes(indexes) } } @@ -54,7 +54,7 @@ extension Persistable where public static func readWithMetadataByKey< ReadTransaction, Metadata where ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(key: String) -> ReadTransaction -> (Self, Metadata?)? { + Metadata: NSCoding>(key: String) -> ReadTransaction -> YapItem? { return { $0.readWithMetadataByKey(key) } } @@ -70,7 +70,7 @@ extension Persistable where Keys: SequenceType, Keys.Generator.Element == String, ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(keys: Keys) -> ReadTransaction -> [(Self, Metadata?)] { + Metadata: NSCoding>(keys: Keys) -> ReadTransaction -> [YapItem] { return { $0.readWithMetadataAtIndexes(Self.indexesWithKeys(keys)) } } @@ -84,7 +84,7 @@ extension Persistable where public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(metadata: Metadata? = nil) -> WriteTransaction -> (Self, Metadata?) { - return { $0.writeWithMetadata((self, metadata)) } + Metadata: NSCoding>(metadata: Metadata? = nil) -> WriteTransaction -> YapItem { + return { $0.writeWithMetadata(YapItem(self, metadata)) } } } diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithValueMetadata.swift index b9b29a4..9dd1702 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ObjectWithValueMetadata.swift @@ -26,7 +26,7 @@ extension Persistable where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> ReadTransaction -> (Self, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> ReadTransaction -> YapItem? { return { $0.readWithMetadataAtIndex(index) } } @@ -44,7 +44,7 @@ extension Persistable where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> ReadTransaction -> [(Self, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> ReadTransaction -> [YapItem] { return { $0.readWithMetadataAtIndexes(indexes) } } @@ -60,7 +60,7 @@ extension Persistable where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> ReadTransaction -> (Self, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(key: String) -> ReadTransaction -> YapItem? { return { $0.readWithMetadataByKey(key) } } @@ -78,7 +78,7 @@ extension Persistable where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> ReadTransaction -> [(Self, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> ReadTransaction -> [YapItem] { return { $0.readWithMetadataAtIndexes(Self.indexesWithKeys(keys)) } } @@ -94,7 +94,7 @@ extension Persistable where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(metadata: Metadata? = nil) -> WriteTransaction -> (Self, Metadata?) { - return { $0.writeWithMetadata((self, metadata)) } + Metadata.Coder.ValueType == Metadata>(metadata: Metadata? = nil) -> WriteTransaction -> YapItem { + return { $0.writeWithMetadata(YapItem(self, metadata)) } } } diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithObjectMetadata.swift index c4c86bd..6ff0779 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithObjectMetadata.swift @@ -26,7 +26,7 @@ extension Persistable where public static func readWithMetadataAtIndex< ReadTransaction, Metadata where ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(index: YapDB.Index) -> ReadTransaction -> (Self, Metadata?)? { + Metadata: NSCoding>(index: YapDB.Index) -> ReadTransaction -> YapItem? { return { $0.readWithMetadataAtIndex(index) } } @@ -42,7 +42,7 @@ extension Persistable where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(indexes: Indexes) -> ReadTransaction -> [(Self, Metadata?)] { + Metadata: NSCoding>(indexes: Indexes) -> ReadTransaction -> [YapItem] { return { $0.readWithMetadataAtIndexes(indexes) } } @@ -56,7 +56,7 @@ extension Persistable where public static func readWithMetadataByKey< ReadTransaction, Metadata where ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(key: String) -> ReadTransaction -> (Self, Metadata?)? { + Metadata: NSCoding>(key: String) -> ReadTransaction -> YapItem? { return { $0.readWithMetadataByKey(key) } } @@ -72,7 +72,7 @@ extension Persistable where Keys: SequenceType, Keys.Generator.Element == String, ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(keys: Keys) -> ReadTransaction -> [(Self, Metadata?)] { + Metadata: NSCoding>(keys: Keys) -> ReadTransaction -> [YapItem] { return { $0.readWithMetadataAtIndexes(Self.indexesWithKeys(keys)) } } @@ -86,7 +86,7 @@ extension Persistable where public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(metadata: Metadata? = nil) -> WriteTransaction -> (Self, Metadata?) { - return { $0.writeWithMetadata((self, metadata)) } + Metadata: NSCoding>(metadata: Metadata? = nil) -> WriteTransaction -> YapItem { + return { $0.writeWithMetadata(YapItem(self, metadata)) } } } diff --git a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithValueMetadata.swift index a3e59fe..4525175 100644 --- a/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Curried/Curried_ValueWithValueMetadata.swift @@ -28,7 +28,7 @@ extension Persistable where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> ReadTransaction -> (Self, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> ReadTransaction -> YapItem? { return { $0.readWithMetadataAtIndex(index) } } @@ -46,7 +46,7 @@ extension Persistable where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> ReadTransaction -> [(Self, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> ReadTransaction -> [YapItem] { return { $0.readWithMetadataAtIndexes(indexes) } } @@ -62,7 +62,7 @@ extension Persistable where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> ReadTransaction -> (Self, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(key: String) -> ReadTransaction -> YapItem? { return { $0.readWithMetadataByKey(key) } } @@ -80,7 +80,7 @@ extension Persistable where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> ReadTransaction -> [(Self, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> ReadTransaction -> [YapItem] { return { $0.readWithMetadataAtIndexes(Self.indexesWithKeys(keys)) } } @@ -96,7 +96,7 @@ extension Persistable where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(metadata: Metadata? = nil) -> WriteTransaction -> (Self, Metadata?) { - return { $0.writeWithMetadata((self, metadata)) } + Metadata.Coder.ValueType == Metadata>(metadata: Metadata? = nil) -> WriteTransaction -> YapItem { + return { $0.writeWithMetadata(YapItem(self, metadata)) } } } diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithObjectMetadata.swift index eb92925..3a9d98d 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithObjectMetadata.swift @@ -24,10 +24,10 @@ extension ReadTransactionType { Object, Metadata where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(index: YapDB.Index) -> (Object, Metadata?)? { + Metadata: NSCoding>(index: YapDB.Index) -> YapItem? { guard let item: Object = readAtIndex(index) else { return nil } let metadata: Metadata? = readMetadataAtIndex(index) - return (item, metadata) + return YapItem(item, metadata) } /** @@ -42,7 +42,7 @@ extension ReadTransactionType { Indexes.Generator.Element == YapDB.Index, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(indexes: Indexes) -> [(Object, Metadata?)] { + Metadata: NSCoding>(indexes: Indexes) -> [YapItem] { // FIXME: using flatMap means the output length need not match the input length return indexes.flatMap(readWithMetadataAtIndex) } @@ -57,7 +57,7 @@ extension ReadTransactionType { Object, Metadata where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(key: String) -> (Object, Metadata?)? { + Metadata: NSCoding>(key: String) -> YapItem? { return readWithMetadataAtIndex(Object.indexWithKey(key)) } @@ -73,7 +73,7 @@ extension ReadTransactionType { Keys.Generator.Element == String, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(keys: Keys) -> [(Object, Metadata?)] { + Metadata: NSCoding>(keys: Keys) -> [YapItem] { return readWithMetadataAtIndexes(Object.indexesWithKeys(keys)) } @@ -86,7 +86,7 @@ extension ReadTransactionType { Object, Metadata where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>() -> [(Object, Metadata?)] { + Metadata: NSCoding>() -> [YapItem] { return readWithMetadataByKeys(keysInCollection(Object.collection)) } } @@ -103,7 +103,7 @@ extension ConnectionType { Object, Metadata where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(index: YapDB.Index) -> (Object, Metadata?)? { + Metadata: NSCoding>(index: YapDB.Index) -> YapItem? { return read { $0.readWithMetadataAtIndex(index) } } @@ -119,7 +119,7 @@ extension ConnectionType { Indexes.Generator.Element == YapDB.Index, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(indexes: Indexes) -> [(Object, Metadata?)] { + Metadata: NSCoding>(indexes: Indexes) -> [YapItem] { return read { $0.readWithMetadataAtIndexes(indexes) } } @@ -133,7 +133,7 @@ extension ConnectionType { Object, Metadata where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(key: String) -> (Object, Metadata?)? { + Metadata: NSCoding>(key: String) -> YapItem? { return readWithMetadataAtIndex(Object.indexWithKey(key)) } @@ -149,7 +149,7 @@ extension ConnectionType { Keys.Generator.Element == String, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(keys: Keys) -> [(Object, Metadata?)] { + Metadata: NSCoding>(keys: Keys) -> [YapItem] { return readWithMetadataAtIndexes(Object.indexesWithKeys(keys)) } @@ -162,7 +162,7 @@ extension ConnectionType { Object, Metadata where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>() -> [(Object, Metadata?)] { + Metadata: NSCoding>() -> [YapItem] { return read { $0.readWithMetadataAll() } } } @@ -180,8 +180,8 @@ extension WriteTransactionType { Object, Metadata where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(item: (Object, Metadata?)) -> (Object, Metadata?) { - writeAtIndex(item.0.index, object: item.0, metadata: item.1) + Metadata: NSCoding>(item: YapItem) -> YapItem { + writeAtIndex(item.value.index, object: item.value, metadata: item.metadata) return item } @@ -193,10 +193,10 @@ extension WriteTransactionType { public func writeWithMetadata< Items, Object, Metadata where Items: SequenceType, - Items.Generator.Element == (Object, Metadata?), + Items.Generator.Element == YapItem, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(items: Items) -> [(Object, Metadata?)] { + Metadata: NSCoding>(items: Items) -> [YapItem] { return items.map(writeWithMetadata) } } @@ -212,7 +212,7 @@ extension ConnectionType { Object, Metadata where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(item: (Object, Metadata?)) -> (Object, Metadata?) { + Metadata: NSCoding>(item: YapItem) -> YapItem { return write { $0.writeWithMetadata(item) } } @@ -224,10 +224,10 @@ extension ConnectionType { public func writeWithMetadata< Items, Object, Metadata where Items: SequenceType, - Items.Generator.Element == (Object, Metadata?), + Items.Generator.Element == YapItem, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(items: Items) -> [(Object, Metadata?)] { + Metadata: NSCoding>(items: Items) -> [YapItem] { return write { $0.writeWithMetadata(items) } } @@ -242,7 +242,7 @@ extension ConnectionType { Object, Metadata where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(item: (Object, Metadata?), queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Object, Metadata?) -> Void)? = .None) { + Metadata: NSCoding>(item: YapItem, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { asyncWrite({ $0.writeWithMetadata(item) }, queue: queue, completion: completion) } @@ -256,10 +256,10 @@ extension ConnectionType { public func asyncWriteWithMetadata< Items, Object, Metadata where Items: SequenceType, - Items.Generator.Element == (Object, Metadata?), + Items.Generator.Element == YapItem, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Object, Metadata?)] -> Void)? = .None) { + Metadata: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { asyncWrite({ $0.writeWithMetadata(items) }, queue: queue, completion: completion) } } diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithValueMetadata.swift index cd0b332..ca78eb5 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ObjectWithValueMetadata.swift @@ -26,10 +26,10 @@ extension ReadTransactionType { Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (Object, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> YapItem? { guard let item: Object = readAtIndex(index) else { return nil } let metadata: Metadata? = readMetadataAtIndex(index) - return (item, metadata) + return YapItem(item, metadata) } /** @@ -46,7 +46,7 @@ extension ReadTransactionType { Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(Object, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [YapItem] { // FIXME: using flatMap means the output length need not match the input length return indexes.flatMap(readWithMetadataAtIndex) } @@ -63,7 +63,7 @@ extension ReadTransactionType { Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> (Object, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(key: String) -> YapItem? { return readWithMetadataAtIndex(Object.indexWithKey(key)) } @@ -81,7 +81,7 @@ extension ReadTransactionType { Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(Object, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [YapItem] { return readWithMetadataAtIndexes(Object.indexesWithKeys(keys)) } @@ -96,7 +96,7 @@ extension ReadTransactionType { Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>() -> [(Object, Metadata?)] { + Metadata.Coder.ValueType == Metadata>() -> [YapItem] { return readWithMetadataByKeys(keysInCollection(Object.collection)) } } @@ -115,7 +115,7 @@ extension ConnectionType { Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (Object, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> YapItem? { return read { $0.readWithMetadataAtIndex(index) } } @@ -133,7 +133,7 @@ extension ConnectionType { Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(Object, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [YapItem] { return read { $0.readWithMetadataAtIndexes(indexes) } } @@ -149,7 +149,7 @@ extension ConnectionType { Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> (Object, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(key: String) -> YapItem? { return readWithMetadataAtIndex(Object.indexWithKey(key)) } @@ -167,7 +167,7 @@ extension ConnectionType { Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(Object, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [YapItem] { return readWithMetadataAtIndexes(Object.indexesWithKeys(keys)) } @@ -182,7 +182,7 @@ extension ConnectionType { Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>() -> [(Object, Metadata?)] { + Metadata.Coder.ValueType == Metadata>() -> [YapItem] { return read { $0.readWithMetadataAll() } } } @@ -202,8 +202,8 @@ extension WriteTransactionType { Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(item: (Object, Metadata?)) -> (Object, Metadata?) { - writeAtIndex(item.0.index, object: item.0, metadata: item.1?.encoded) + Metadata.Coder.ValueType == Metadata>(item: YapItem) -> YapItem { + writeAtIndex(item.value.index, object: item.value, metadata: item.metadata?.encoded) return item } @@ -215,12 +215,12 @@ extension WriteTransactionType { public func writeWithMetadata< Items, Object, Metadata where Items: SequenceType, - Items.Generator.Element == (Object, Metadata?), + Items.Generator.Element == YapItem, Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(items: Items) -> [(Object, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(items: Items) -> [YapItem] { return items.map(writeWithMetadata) } } @@ -238,7 +238,7 @@ extension ConnectionType { Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(item: (Object, Metadata?)) -> (Object, Metadata?) { + Metadata.Coder.ValueType == Metadata>(item: YapItem) -> YapItem { return write { $0.writeWithMetadata(item) } } @@ -250,12 +250,12 @@ extension ConnectionType { public func writeWithMetadata< Items, Object, Metadata where Items: SequenceType, - Items.Generator.Element == (Object, Metadata?), + Items.Generator.Element == YapItem, Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(items: Items) -> [(Object, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(items: Items) -> [YapItem] { return write { $0.writeWithMetadata(items) } } @@ -272,7 +272,7 @@ extension ConnectionType { Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(item: (Object, Metadata?), queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Object, Metadata?) -> Void)? = .None) { + Metadata.Coder.ValueType == Metadata>(item: YapItem, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { asyncWrite({ $0.writeWithMetadata(item) }, queue: queue, completion: completion) } @@ -286,12 +286,12 @@ extension ConnectionType { public func asyncWriteWithMetadata< Items, Object, Metadata where Items: SequenceType, - Items.Generator.Element == (Object, Metadata?), + Items.Generator.Element == YapItem, Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Object, Metadata?)] -> Void)? = .None) { + Metadata.Coder.ValueType == Metadata>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { asyncWrite({ $0.writeWithMetadata(items) }, queue: queue, completion: completion) } } diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthObjectMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthObjectMetadata.swift index 1b14983..ce9f5b8 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthObjectMetadata.swift @@ -26,10 +26,10 @@ extension ReadTransactionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(index: YapDB.Index) -> (Value, Metadata?)? { + Metadata: NSCoding>(index: YapDB.Index) -> YapItem? { guard let item: Value = Value.decode(readAtIndex(index)) else { return nil } let metadata: Metadata? = readMetadataAtIndex(index) - return (item, metadata) + return YapItem(item, metadata) } /** @@ -46,7 +46,7 @@ extension ReadTransactionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(indexes: Indexes) -> [(Value, Metadata?)] { + Metadata: NSCoding>(indexes: Indexes) -> [YapItem] { // FIXME: using flatMap means the output length need not match the input length return indexes.flatMap(readWithMetadataAtIndex) } @@ -63,7 +63,7 @@ extension ReadTransactionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(key: String) -> (Value, Metadata?)? { + Metadata: NSCoding>(key: String) -> YapItem? { return readWithMetadataAtIndex(Value.indexWithKey(key)) } @@ -81,7 +81,7 @@ extension ReadTransactionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(keys: Keys) -> [(Value, Metadata?)] { + Metadata: NSCoding>(keys: Keys) -> [YapItem] { return readWithMetadataAtIndexes(Value.indexesWithKeys(keys)) } @@ -96,7 +96,7 @@ extension ReadTransactionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>() -> [(Value, Metadata?)] { + Metadata: NSCoding>() -> [YapItem] { return readWithMetadataByKeys(keysInCollection(Value.collection)) } } @@ -115,7 +115,7 @@ extension ConnectionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(index: YapDB.Index) -> (Value, Metadata?)? { + Metadata: NSCoding>(index: YapDB.Index) -> YapItem? { return read { $0.readWithMetadataAtIndex(index) } } @@ -133,7 +133,7 @@ extension ConnectionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(indexes: Indexes) -> [(Value, Metadata?)] { + Metadata: NSCoding>(indexes: Indexes) -> [YapItem] { return read { $0.readWithMetadataAtIndexes(indexes) } } @@ -149,7 +149,7 @@ extension ConnectionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(key: String) -> (Value, Metadata?)? { + Metadata: NSCoding>(key: String) -> YapItem? { return readWithMetadataAtIndex(Value.indexWithKey(key)) } @@ -167,7 +167,7 @@ extension ConnectionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(keys: Keys) -> [(Value, Metadata?)] { + Metadata: NSCoding>(keys: Keys) -> [YapItem] { return readWithMetadataAtIndexes(Value.indexesWithKeys(keys)) } @@ -182,7 +182,7 @@ extension ConnectionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>() -> [(Value, Metadata?)] { + Metadata: NSCoding>() -> [YapItem] { return read { $0.readWithMetadataAll() } } } @@ -202,8 +202,8 @@ extension WriteTransactionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(item: (Value, Metadata?)) -> (Value, Metadata?) { - writeAtIndex(item.0.index, object: item.0.encoded, metadata: item.1) + Metadata: NSCoding>(item: YapItem) -> YapItem { + writeAtIndex(item.value.index, object: item.value.encoded, metadata: item.metadata) return item } @@ -215,12 +215,12 @@ extension WriteTransactionType { public func writeWithMetadata< Items, Value, Metadata where Items: SequenceType, - Items.Generator.Element == (Value, Metadata?), + Items.Generator.Element == YapItem, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(items: Items) -> [(Value, Metadata?)] { + Metadata: NSCoding>(items: Items) -> [YapItem] { return items.map(writeWithMetadata) } } @@ -238,7 +238,7 @@ extension ConnectionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(item: (Value, Metadata?)) -> (Value, Metadata?) { + Metadata: NSCoding>(item: YapItem) -> YapItem { return write { $0.writeWithMetadata(item) } } @@ -250,12 +250,12 @@ extension ConnectionType { public func writeWithMetadata< Items, Value, Metadata where Items: SequenceType, - Items.Generator.Element == (Value, Metadata?), + Items.Generator.Element == YapItem, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(items: Items) -> [(Value, Metadata?)] { + Metadata: NSCoding>(items: Items) -> [YapItem] { return write { $0.writeWithMetadata(items) } } @@ -272,7 +272,7 @@ extension ConnectionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(item: (Value, Metadata?), queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Value, Metadata?) -> Void)? = .None) { + Metadata: NSCoding>(item: YapItem, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { asyncWrite({ $0.writeWithMetadata(item) }, queue: queue, completion: completion) } @@ -286,12 +286,12 @@ extension ConnectionType { public func asyncWriteWithMetadata< Items, Value, Metadata where Items: SequenceType, - Items.Generator.Element == (Value, Metadata?), + Items.Generator.Element == YapItem, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, - Metadata: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Value, Metadata?)] -> Void)? = .None) { + Metadata: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { asyncWrite({ $0.writeWithMetadata(items) }, queue: queue, completion: completion) } } diff --git a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthValueMetadata.swift b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthValueMetadata.swift index ea95096..19fb418 100644 --- a/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Functional/Functional_ValueWIthValueMetadata.swift @@ -28,10 +28,10 @@ extension ReadTransactionType { Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (Value, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> YapItem? { guard let item: Value = Value.decode(readAtIndex(index)) else { return nil } let metadata: Metadata? = readMetadataAtIndex(index) - return (item, metadata) + return YapItem(item, metadata) } /** @@ -50,7 +50,7 @@ extension ReadTransactionType { Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(Value, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [YapItem] { // FIXME: using flatMap means the output length need not match the input length return indexes.flatMap(readWithMetadataAtIndex) } @@ -69,7 +69,7 @@ extension ReadTransactionType { Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> (Value, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(key: String) -> YapItem? { return readWithMetadataAtIndex(Value.indexWithKey(key)) } @@ -89,7 +89,7 @@ extension ReadTransactionType { Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(Value, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [YapItem] { return readWithMetadataAtIndexes(Value.indexesWithKeys(keys)) } @@ -106,7 +106,7 @@ extension ReadTransactionType { Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>() -> [(Value, Metadata?)] { + Metadata.Coder.ValueType == Metadata>() -> [YapItem] { return readWithMetadataByKeys(keysInCollection(Value.collection)) } } @@ -127,7 +127,7 @@ extension ConnectionType { Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (Value, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> YapItem? { return read { $0.readWithMetadataAtIndex(index) } } @@ -147,7 +147,7 @@ extension ConnectionType { Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(Value, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [YapItem] { return read { $0.readWithMetadataAtIndexes(indexes) } } @@ -165,7 +165,7 @@ extension ConnectionType { Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> (Value, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(key: String) -> YapItem? { return readWithMetadataAtIndex(Value.indexWithKey(key)) } @@ -185,7 +185,7 @@ extension ConnectionType { Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(Value, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [YapItem] { return readWithMetadataAtIndexes(Value.indexesWithKeys(keys)) } @@ -202,7 +202,7 @@ extension ConnectionType { Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>() -> [(Value, Metadata?)] { + Metadata.Coder.ValueType == Metadata>() -> [YapItem] { return read { $0.readWithMetadataAll() } } } @@ -224,8 +224,8 @@ extension WriteTransactionType { Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(item: (Value, Metadata?)) -> (Value, Metadata?) { - writeAtIndex(item.0.index, object: item.0.encoded, metadata: item.1?.encoded) + Metadata.Coder.ValueType == Metadata>(item: YapItem) -> YapItem { + writeAtIndex(item.value.index, object: item.value.encoded, metadata: item.metadata?.encoded) return item } @@ -237,14 +237,14 @@ extension WriteTransactionType { public func writeWithMetadata< Items, Value, Metadata where Items: SequenceType, - Items.Generator.Element == (Value, Metadata?), + Items.Generator.Element == YapItem, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(items: Items) -> [(Value, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(items: Items) -> [YapItem] { return items.map(writeWithMetadata) } } @@ -264,7 +264,7 @@ extension ConnectionType { Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(item: (Value, Metadata?)) -> (Value, Metadata?) { + Metadata.Coder.ValueType == Metadata>(item: YapItem) -> YapItem { return write { $0.writeWithMetadata(item) } } @@ -276,14 +276,14 @@ extension ConnectionType { public func writeWithMetadata< Items, Value, Metadata where Items: SequenceType, - Items.Generator.Element == (Value, Metadata?), + Items.Generator.Element == YapItem, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(items: Items) -> [(Value, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(items: Items) -> [YapItem] { return write { $0.writeWithMetadata(items) } } @@ -302,7 +302,7 @@ extension ConnectionType { Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(item: (Value, Metadata?), queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Value, Metadata?) -> Void)? = .None) { + Metadata.Coder.ValueType == Metadata>(item: YapItem, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { asyncWrite({ $0.writeWithMetadata(item) }, queue: queue, completion: completion) } @@ -316,14 +316,14 @@ extension ConnectionType { public func asyncWriteWithMetadata< Items, Value, Metadata where Items: SequenceType, - Items.Generator.Element == (Value, Metadata?), + Items.Generator.Element == YapItem, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.ValueType == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Value, Metadata?)] -> Void)? = .None) { + Metadata.Coder.ValueType == Metadata>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { asyncWrite({ $0.writeWithMetadata(items) }, queue: queue, completion: completion) } } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift index 0d86004..abc3f22 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithObjectMetadata.swift @@ -24,8 +24,8 @@ extension Persistable where public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { - return transaction.writeWithMetadata((self, metadata)) + Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata?) -> YapItem { + return transaction.writeWithMetadata(YapItem(self, metadata)) } /** @@ -37,8 +37,8 @@ extension Persistable where public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { - return connection.writeWithMetadata((self, metadata)) + Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> YapItem { + return connection.writeWithMetadata(YapItem(self, metadata)) } /** @@ -50,8 +50,8 @@ extension Persistable where public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { - return connection.asyncWriteWithMetadata((self, metadata), queue: queue, completion: completion) + Metadata: NSCoding>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { + return connection.asyncWriteWithMetadata(YapItem(self, metadata), queue: queue, completion: completion) } /** @@ -64,7 +64,7 @@ extension Persistable where Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> NSOperation { - return NSBlockOperation { connection.writeWithMetadata((self, metadata)) } + return NSBlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } } } @@ -72,6 +72,21 @@ extension SequenceType where Generator.Element: Persistable, Generator.Element: NSCoding { + /** + Zips the receiver with metadata into an array of YapItem. + Assumes `self` and `metadata` have the same `count`. + + - parameter metadata: a sequence of optional metadatas. + - returns: an array where Persistables and Metadata with corresponding indexes in `self` and `metadata` are joined in a `YapItem` + */ + public func yapItems< + Metadatas, Metadata where + Metadata: NSCoding, + Metadatas: SequenceType, + Metadatas.Generator.Element == Optional>(with metadata: Metadatas) -> [YapItem] { + return zip(self, metadata).map { YapItem($0, $1) } + } + /** Write the items using an existing transaction. @@ -81,8 +96,8 @@ extension SequenceType where public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { - let items = zipToWrite(self, metadata) + Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] { + let items = yapItems(with: metadata) return transaction.writeWithMetadata(items) } @@ -95,8 +110,8 @@ extension SequenceType where public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { - let items = zipToWrite(self, metadata) + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> [YapItem] { + let items = yapItems(with: metadata) return connection.writeWithMetadata(items) } @@ -109,8 +124,8 @@ extension SequenceType where public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { - let items = zipToWrite(self, metadata) + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { + let items = yapItems(with: metadata) return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } @@ -124,7 +139,7 @@ extension SequenceType where Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> NSOperation { - let items = zipToWrite(self, metadata) + let items = yapItems(with: metadata) return NSBlockOperation { connection.writeWithMetadata(items) } } } @@ -136,15 +151,15 @@ extension Readable where ItemType: NSCoding, ItemType: Persistable { - func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { + func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> YapItem? { return transaction.readWithMetadataAtIndex(index) } - func withMetadataInTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { + func withMetadataInTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> YapItem? { return { self.withMetadataInTransaction(transaction, atIndex: $0) } } - func withMetadataAtIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { + func withMetadataAtIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> YapItem? { return { self.withMetadataInTransaction($0, atIndex: index) } } @@ -152,23 +167,23 @@ extension Readable where Indexes, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - Metadata: NSCoding>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + Metadata: NSCoding>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [YapItem] { return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } } - func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { + func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? { return withMetadataInTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func withMetadataInTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { + func withMetadataInTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> YapItem? { return { self.withMetadataInTransaction(transaction, byKey: $0) } } - func withMetadataByKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { + func withMetadataByKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> YapItem? { return { self.withMetadataInTransaction($0, byKey: key) } } - func withMetadataByKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + func withMetadataByKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [YapItem] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) @@ -181,7 +196,7 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func withMetadataAtIndex(index: YapDB.Index) -> (ItemType, Metadata?)? { + public func withMetadataAtIndex(index: YapDB.Index) -> YapItem? { return sync(withMetadataAtIndexInTransaction(index)) } @@ -195,7 +210,7 @@ extension Readable where Indexes, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - Metadata: NSCoding>(indexes: Indexes) -> [(ItemType, Metadata?)] { + Metadata: NSCoding>(indexes: Indexes) -> [YapItem] { return sync(withMetadataAtIndexesInTransaction(indexes)) } @@ -205,7 +220,7 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func withMetadataByKey(key: String) -> (ItemType, Metadata?)? { + public func withMetadataByKey(key: String) -> YapItem? { return sync(withMetadataByKeyInTransaction(key)) } @@ -219,7 +234,7 @@ extension Readable where Keys, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - Metadata: NSCoding>(keys: Keys) -> [(ItemType, Metadata?)] { + Metadata: NSCoding>(keys: Keys) -> [YapItem] { return sync(withMetadataByKeysInTransaction(Array(keys))) } @@ -228,7 +243,7 @@ extension Readable where - returns: an array of `ItemType` */ - public func withMetadataAll() -> [(ItemType, Metadata?)] { + public func withMetadataAll() -> [YapItem] { return sync(withMetadataByKeysInTransaction()) } @@ -238,11 +253,11 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func withMetadataFilterExisting(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { - let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = withMetadataByKeysInTransaction(keys) - return sync { transaction -> ([(ItemType, Metadata?)], [String]) in + public func withMetadataFilterExisting(keys: [String]) -> (existing: [YapItem], missing: [String]) { + let existingInTransaction: Database.Connection.ReadTransaction -> [YapItem] = withMetadataByKeysInTransaction(keys) + return sync { transaction -> ([YapItem], [String]) in let existing = existingInTransaction(transaction) - let existingKeys = existing.map {keyForPersistable($0.0)} + let existingKeys = existing.map {keyForPersistable($0.value)} let missingKeys = keys.filter { !existingKeys.contains($0) } return (existing, missingKeys) } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift index 06a9570..3ca949f 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ObjectWithValueMetadata.swift @@ -27,8 +27,8 @@ extension Persistable where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { - return transaction.writeWithMetadata((self, metadata)) + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata?) -> YapItem { + return transaction.writeWithMetadata(YapItem(self, metadata)) } /** @@ -42,8 +42,8 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { - return connection.writeWithMetadata((self, metadata)) + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> YapItem { + return connection.writeWithMetadata(YapItem(self, metadata)) } /** @@ -57,8 +57,8 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { - return connection.asyncWriteWithMetadata((self, metadata), queue: queue, completion: completion) + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { + return connection.asyncWriteWithMetadata(YapItem(self, metadata), queue: queue, completion: completion) } /** @@ -73,7 +73,7 @@ extension Persistable where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> NSOperation { - return NSBlockOperation { connection.writeWithMetadata((self, metadata)) } + return NSBlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } } } @@ -81,6 +81,23 @@ extension SequenceType where Generator.Element: Persistable, Generator.Element: NSCoding { + /** + Zips the receiver with metadata into an array of YapItem. + Assumes `self` and `metadata` have the same `count`. + + - parameter metadata: a sequence of optional metadatas. + - returns: an array where Persistables and Metadata with corresponding indexes in `self` and `metadata` are joined in a `YapItem` + */ + public func yapItems< + Metadatas, Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata, + Metadatas: SequenceType, + Metadatas.Generator.Element == Optional>(with metadata: Metadatas) -> [YapItem] { + return zip(self, metadata).map { YapItem($0, $1) } + } + /** Write the items using an existing transaction. @@ -92,8 +109,8 @@ extension SequenceType where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { - let items = zipToWrite(self, metadata) + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] { + let items = yapItems(with: metadata) return transaction.writeWithMetadata(items) } @@ -108,8 +125,8 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { - let items = zipToWrite(self, metadata) + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> [YapItem] { + let items = yapItems(with: metadata) return connection.writeWithMetadata(items) } @@ -124,8 +141,8 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { - let items = zipToWrite(self, metadata) + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { + let items = yapItems(with: metadata) return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } @@ -141,7 +158,7 @@ extension SequenceType where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> NSOperation { - let items = zipToWrite(self, metadata) + let items = yapItems(with: metadata) return NSBlockOperation { connection.writeWithMetadata(items) } } } @@ -156,7 +173,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> YapItem? { return transaction.readWithMetadataAtIndex(index) } @@ -164,7 +181,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> YapItem? { return { self.withMetadataInTransaction(transaction, atIndex: $0) } } @@ -172,7 +189,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Database.Connection.ReadTransaction -> YapItem? { return { self.withMetadataInTransaction($0, atIndex: index) } } @@ -182,7 +199,7 @@ extension Readable where Indexes.Generator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [YapItem] { return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } } @@ -190,7 +207,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? { return withMetadataInTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } @@ -198,7 +215,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> String -> YapItem? { return { self.withMetadataInTransaction(transaction, byKey: $0) } } @@ -206,7 +223,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(key: String) -> Database.Connection.ReadTransaction -> YapItem? { return { self.withMetadataInTransaction($0, byKey: key) } } @@ -214,7 +231,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [YapItem] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) @@ -231,7 +248,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> YapItem? { return sync(withMetadataAtIndexInTransaction(index)) } @@ -247,7 +264,7 @@ extension Readable where Indexes.Generator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(ItemType, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [YapItem] { return sync(withMetadataAtIndexesInTransaction(indexes)) } @@ -261,7 +278,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(key: String) -> YapItem? { return sync(withMetadataByKeyInTransaction(key)) } @@ -277,7 +294,7 @@ extension Readable where Keys.Generator.Element == String, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(ItemType, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [YapItem] { return sync(withMetadataByKeysInTransaction(Array(keys))) } @@ -290,7 +307,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>() -> [(ItemType, Metadata?)] { + Metadata.Coder.ValueType == Metadata>() -> [YapItem] { return sync(withMetadataByKeysInTransaction()) } @@ -304,11 +321,11 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { - let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = withMetadataByKeysInTransaction(keys) - return sync { transaction -> ([(ItemType, Metadata?)], [String]) in + Metadata.Coder.ValueType == Metadata>(keys: [String]) -> (existing: [YapItem], missing: [String]) { + let existingInTransaction: Database.Connection.ReadTransaction -> [YapItem] = withMetadataByKeysInTransaction(keys) + return sync { transaction -> ([YapItem], [String]) in let existing = existingInTransaction(transaction) - let existingKeys = existing.map {keyForPersistable($0.0)} + let existingKeys = existing.map {keyForPersistable($0.value)} let missingKeys = keys.filter { !existingKeys.contains($0) } return (existing, missingKeys) } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift index 2a200dd..bbabc82 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithObjectMetadata.swift @@ -27,8 +27,8 @@ extension Persistable where public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { - return transaction.writeWithMetadata((self, metadata)) + Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata?) -> YapItem { + return transaction.writeWithMetadata(YapItem(self, metadata)) } /** @@ -40,8 +40,8 @@ extension Persistable where public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { - return connection.writeWithMetadata((self, metadata)) + Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> YapItem { + return connection.writeWithMetadata(YapItem(self, metadata)) } /** @@ -53,8 +53,8 @@ extension Persistable where public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { - return connection.asyncWriteWithMetadata((self, metadata), queue: queue, completion: completion) + Metadata: NSCoding>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { + return connection.asyncWriteWithMetadata(YapItem(self, metadata), queue: queue, completion: completion) } /** @@ -67,7 +67,7 @@ extension Persistable where Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> NSOperation { - return NSBlockOperation { connection.writeWithMetadata((self, metadata)) } + return NSBlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } } } @@ -77,6 +77,21 @@ extension SequenceType where Generator.Element.Coder: NSCoding, Generator.Element.Coder.ValueType == Generator.Element { + /** + Zips the receiver with metadata into an array of YapItem. + Assumes `self` and `metadata` have the same `count`. + + - parameter metadata: a sequence of optional metadatas. + - returns: an array where Persistables and Metadata with corresponding indexes in `self` and `metadata` are joined in a `YapItem` + */ + public func yapItems< + Metadatas, Metadata where + Metadata: NSCoding, + Metadatas: SequenceType, + Metadatas.Generator.Element == Optional>(with metadata: Metadatas) -> [YapItem] { + return zip(self, metadata).map { YapItem($0, $1) } + } + /** Write the items using an existing transaction. @@ -86,8 +101,8 @@ extension SequenceType where public func writeWithMetadata< WriteTransaction, Metadata where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { - let items = zipToWrite(self, metadata) + Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] { + let items = yapItems(with: metadata) return transaction.writeWithMetadata(items) } @@ -100,8 +115,8 @@ extension SequenceType where public func writeWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { - let items = zipToWrite(self, metadata) + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> [YapItem] { + let items = yapItems(with: metadata) return connection.writeWithMetadata(items) } @@ -114,8 +129,8 @@ extension SequenceType where public func asyncWriteWithMetadata< Connection, Metadata where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { - let items = zipToWrite(self, metadata) + Metadata: NSCoding>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { + let items = yapItems(with: metadata) return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } @@ -129,7 +144,7 @@ extension SequenceType where Connection, Metadata where Connection: ConnectionType, Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> NSOperation { - let items = zipToWrite(self, metadata) + let items = yapItems(with: metadata) return NSBlockOperation { connection.writeWithMetadata(items) } } } @@ -143,15 +158,15 @@ extension Readable where ItemType.Coder: NSCoding, ItemType.Coder.ValueType == ItemType { - func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { + func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> YapItem? { return transaction.readWithMetadataAtIndex(index) } - func withMetadataInTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { + func withMetadataInTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> YapItem? { return { self.withMetadataInTransaction(transaction, atIndex: $0) } } - func withMetadataAtIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { + func withMetadataAtIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> YapItem? { return { self.withMetadataInTransaction($0, atIndex: index) } } @@ -159,23 +174,23 @@ extension Readable where Indexes, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - Metadata: NSCoding>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + Metadata: NSCoding>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [YapItem] { return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } } - func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { + func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? { return withMetadataInTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func withMetadataInTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { + func withMetadataInTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> YapItem? { return { self.withMetadataInTransaction(transaction, byKey: $0) } } - func withMetadataByKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { + func withMetadataByKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> YapItem? { return { self.withMetadataInTransaction($0, byKey: key) } } - func withMetadataByKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + func withMetadataByKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [YapItem] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) @@ -188,7 +203,7 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func withMetadataAtIndex(index: YapDB.Index) -> (ItemType, Metadata?)? { + public func withMetadataAtIndex(index: YapDB.Index) -> YapItem? { return sync(withMetadataAtIndexInTransaction(index)) } @@ -202,7 +217,7 @@ extension Readable where Indexes, Metadata where Indexes: SequenceType, Indexes.Generator.Element == YapDB.Index, - Metadata: NSCoding>(indexes: Indexes) -> [(ItemType, Metadata?)] { + Metadata: NSCoding>(indexes: Indexes) -> [YapItem] { return sync(withMetadataAtIndexesInTransaction(indexes)) } @@ -212,7 +227,7 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func withMetadataByKey(key: String) -> (ItemType, Metadata?)? { + public func withMetadataByKey(key: String) -> YapItem? { return sync(withMetadataByKeyInTransaction(key)) } @@ -226,7 +241,7 @@ extension Readable where Keys, Metadata where Keys: SequenceType, Keys.Generator.Element == String, - Metadata: NSCoding>(keys: Keys) -> [(ItemType, Metadata?)] { + Metadata: NSCoding>(keys: Keys) -> [YapItem] { return sync(withMetadataByKeysInTransaction(Array(keys))) } @@ -235,7 +250,7 @@ extension Readable where - returns: an array of `ItemType` */ - public func withMetadataAll() -> [(ItemType, Metadata?)] { + public func withMetadataAll() -> [YapItem] { return sync(withMetadataByKeysInTransaction()) } @@ -245,11 +260,11 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func withMetadataFilterExisting(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { - let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = withMetadataByKeysInTransaction(keys) - return sync { transaction -> ([(ItemType, Metadata?)], [String]) in + public func withMetadataFilterExisting(keys: [String]) -> (existing: [YapItem], missing: [String]) { + let existingInTransaction: Database.Connection.ReadTransaction -> [YapItem] = withMetadataByKeysInTransaction(keys) + return sync { transaction -> ([YapItem], [String]) in let existing = existingInTransaction(transaction) - let existingKeys = existing.map {keyForPersistable($0.0)} + let existingKeys = existing.map {keyForPersistable($0.value)} let missingKeys = keys.filter { !existingKeys.contains($0) } return (existing, missingKeys) } diff --git a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift index 5dea161..c7c4912 100644 --- a/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift +++ b/YapDatabaseExtensions/Shared/Persistable/Persistable_ValueWithValueMetadata.swift @@ -29,8 +29,8 @@ extension Persistable where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata?) -> (Self, Metadata?) { - return transaction.writeWithMetadata((self, metadata)) + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata?) -> YapItem { + return transaction.writeWithMetadata(YapItem(self, metadata)) } /** @@ -44,8 +44,8 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> (Self, Metadata?) { - return connection.writeWithMetadata((self, metadata)) + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> YapItem { + return connection.writeWithMetadata(YapItem(self, metadata)) } /** @@ -59,8 +59,8 @@ extension Persistable where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self, Metadata?) -> Void)? = .None) { - return connection.asyncWriteWithMetadata((self, metadata), queue: queue, completion: completion) + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { + return connection.asyncWriteWithMetadata(YapItem(self, metadata), queue: queue, completion: completion) } /** @@ -75,7 +75,7 @@ extension Persistable where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> NSOperation { - return NSBlockOperation { connection.writeWithMetadata((self, metadata)) } + return NSBlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } } } @@ -85,6 +85,23 @@ extension SequenceType where Generator.Element.Coder: NSCoding, Generator.Element.Coder.ValueType == Generator.Element { + /** + Zips the receiver with metadata into an array of YapItem. + Assumes `self` and `metadata` have the same `count`. + + - parameter metadata: a sequence of optional metadatas. + - returns: an array where Persistables and Metadata with corresponding indexes in `self` and `metadata` are joined in a `YapItem` + */ + public func yapItems< + Metadatas, Metadata where + Metadata: ValueCoding, + Metadata.Coder: NSCoding, + Metadata.Coder.ValueType == Metadata, + Metadatas: SequenceType, + Metadatas.Generator.Element == Optional>(with metadata: Metadatas) -> [YapItem] { + return zip(self, metadata).map { YapItem($0, $1) } + } + /** Write the items using an existing transaction. @@ -96,8 +113,8 @@ extension SequenceType where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { - let items = zipToWrite(self, metadata) + Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] { + let items = yapItems(with: metadata) return transaction.writeWithMetadata(items) } @@ -112,8 +129,8 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> [(Generator.Element, Metadata?)] { - let items = zipToWrite(self, metadata) + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> [YapItem] { + let items = yapItems(with: metadata) return connection.writeWithMetadata(items) } @@ -128,8 +145,8 @@ extension SequenceType where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([(Generator.Element, Metadata?)] -> Void)? = .None) { - let items = zipToWrite(self, metadata) + Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { + let items = yapItems(with: metadata) return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } @@ -145,7 +162,7 @@ extension SequenceType where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> NSOperation { - let items = zipToWrite(self, metadata) + let items = yapItems(with: metadata) return NSBlockOperation { connection.writeWithMetadata(items) } } } @@ -162,7 +179,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> YapItem? { return transaction.readWithMetadataAtIndex(index) } @@ -170,7 +187,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> YapItem? { return { self.withMetadataInTransaction(transaction, atIndex: $0) } } @@ -178,7 +195,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Database.Connection.ReadTransaction -> YapItem? { return { self.withMetadataInTransaction($0, atIndex: index) } } @@ -188,7 +205,7 @@ extension Readable where Indexes.Generator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [YapItem] { return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } } @@ -196,7 +213,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, byKey key: String) -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? { return withMetadataInTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } @@ -204,7 +221,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> String -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> String -> YapItem? { return { self.withMetadataInTransaction(transaction, byKey: $0) } } @@ -212,7 +229,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> Database.Connection.ReadTransaction -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(key: String) -> Database.Connection.ReadTransaction -> YapItem? { return { self.withMetadataInTransaction($0, byKey: key) } } @@ -220,7 +237,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [YapItem] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) @@ -237,7 +254,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> YapItem? { return sync(withMetadataAtIndexInTransaction(index)) } @@ -253,7 +270,7 @@ extension Readable where Indexes.Generator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [(ItemType, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [YapItem] { return sync(withMetadataAtIndexesInTransaction(indexes)) } @@ -267,7 +284,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> (ItemType, Metadata?)? { + Metadata.Coder.ValueType == Metadata>(key: String) -> YapItem? { return sync(withMetadataByKeyInTransaction(key)) } @@ -283,7 +300,7 @@ extension Readable where Keys.Generator.Element == String, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [(ItemType, Metadata?)] { + Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [YapItem] { return sync(withMetadataByKeysInTransaction(Array(keys))) } @@ -296,7 +313,7 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>() -> [(ItemType, Metadata?)] { + Metadata.Coder.ValueType == Metadata>() -> [YapItem] { return sync(withMetadataByKeysInTransaction()) } @@ -310,11 +327,11 @@ extension Readable where Metadata where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: [String]) -> (existing: [(ItemType, Metadata?)], missing: [String]) { - let existingInTransaction: Database.Connection.ReadTransaction -> [(ItemType, Metadata?)] = withMetadataByKeysInTransaction(keys) - return sync { transaction -> ([(ItemType, Metadata?)], [String]) in + Metadata.Coder.ValueType == Metadata>(keys: [String]) -> (existing: [YapItem], missing: [String]) { + let existingInTransaction: Database.Connection.ReadTransaction -> [YapItem] = withMetadataByKeysInTransaction(keys) + return sync { transaction -> ([YapItem], [String]) in let existing = existingInTransaction(transaction) - let existingKeys = existing.map {keyForPersistable($0.0)} + let existingKeys = existing.map {keyForPersistable($0.value)} let missingKeys = keys.filter { !existingKeys.contains($0) } return (existing, missingKeys) } diff --git a/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift b/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift index aa3a1b8..b6cf121 100644 --- a/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift +++ b/YapDatabaseExtensions/Shared/YapDatabaseExtensions.swift @@ -119,16 +119,6 @@ public struct YapDB { } } -public func zipToWrite< - Value, Values, Metadata, Metadatas where - Values: SequenceType, - Values.Generator.Element == Value, - Metadatas: SequenceType, - Metadatas.Generator.Element == Metadata - >(values: Values, _ metadatas: Metadatas) -> [(Value, Metadata)] { - return zip(values, metadatas).map { ($0, $1) } -} - extension YapDB { /** @@ -155,6 +145,30 @@ extension YapDB { } } +/** +A pairing (effectively a tuple) of a value and a metadata. +Used when values and metadatas are read or written together. +*/ +public struct YapItem { + + /// The item's value + let value: Value + + /// The item's metadata + let metadata: Metadata? + + /** + Create a new YapItem value. + + - parameter value: the value associated with a `YapDB.Index` + - parameter metadata: an optional metadata associated with a `YapDB.Index` + */ + public init(_ value: Value, _ metadata: Metadata?) { + self.value = value + self.metadata = metadata + } +} + // MARK: - Identifiable /** From 1ed4c10556c63b61f978f6a536f4355d9474fb6f Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 15 Sep 2016 23:38:33 -0700 Subject: [PATCH 14/54] some updates to README.md --- README.md | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 9292a00..59847f1 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ public protocol Identifiable { public protocol Persistable: Identifiable { static var collection: String { get } - var metadata: MetadataType? { get set } } ``` @@ -41,26 +40,11 @@ While not a requirement of YapDatabase, for these extensions, it is required tha There is also a `YapDB.Index` struct which composes the key and collection into a single type. This is used internally for all access methods. Properties defined in an extension on `Persistable` provide access to `key` and `index`. ### Metadata -YapDatabase supports storing metadata alongside the primary object. YapDatabaseExtensions supports automatic reading and writing of metadata as an optional property of the `Persistable` type. +YapDatabase supports storing metadata alongside the primary object. YapDatabaseExtensions supports optional reading and writing of metadata alongside a `Persistable` type. -By default, all types which conform to `Persistable`, will get a `MetadataType` of `Void` which is synthesized by default. Therefore if you do not want or need a metadata type, there is nothing to do. +Your custom metadata types must conform to either `NSCoding` or `ValueCoding`. -To support a custom metadata type, just add the following to your `Persistable` type, e.g.: - -```swift -struct MyCustomValue: Persistable, ValueCoding { - typealias Coder = MyCustomValueCoder - static let collection = “MyCustomValues” - var metadata: MyCustomMetadata? = .None - let identifier: NSUUID -} -``` - -where the type (`MyCustomMetadata` in the above snippet) implements either `NSCoding` or `ValueCoding`. - -When creating a new item, set the metadata property before saving the item to the database. YapDatabaseExtensions will then save the metadata inside YapDatabase correctly. *There is no need to encode the metadata inside the primary object*. When reading objects which have a valid `MetadataType`, YapDatabaseExtensions will automatically read, decode and set the item’s metadata before returning the item. - -Note that previous metadata protocols `ObjectMetadataPersistable` and `ValueMetadataPersistable` have been deprecated in favor of `Persistable`. +In this version of YapDatabaseExtensions, metadata has been removed from `Persistable`, and all reads and writes of metadata must be done explicitly. Additionally, since the `MetadataType` is decoupled from the `Persistable` type, a single `Persistable` type can use many different types of metadata, as appropriate. When you want to read or write a value and it's metadata together, you use the "withMetadata" variants of the API, which accept and return `YapItem` values. `YapItem` is basically a slightly nicer wrapper than a Swift tuple, which can be extended, unlike anonymous tuple types. ## “Correct” Type Patterns Because the generic protocols, `ValueCoding` and `CodingType` have self-reflective properties, they must be correctly implemented for the APIs to be available. This means that the equality `ValueCoding.Coder.ValueType == Self` must be met. The APIs are all composed with this represented in their generic where clauses. This means that if your `ValueCoding` type is not the `ValueType` of its `Coder`, your code will not compile. @@ -69,10 +53,10 @@ Therefore, there are six valid `Persistable` type patterns as described in the t Item encoding | Metadata encoding | Pattern --------------|-------------------|------------------ -`NSCoding` | `Void` Metadata | Object +`NSCoding` | No Metadata | Object `NSCoding` | `NSCoding` | ObjectWithObjectMetadata `NSCoding` | `ValueCoding` | ObjectWithValueMetadata -`ValueCoding` | `Void` Metadata | Value +`ValueCoding` | No Metadata | Value `ValueCoding` | `NSCoding` | ValueWithObjectMetadata `ValueCoding` | `ValueCoding` | ValueWithValueMetadata @@ -118,7 +102,7 @@ if let item: Item? = connection.readAtIndex(index) { // etc } -if let meta: Item.MetadataType? = connection.readMetadataAtIndex(index) { +if let meta: MetadataType? = connection.readMetadataAtIndex(index) { // etc } @@ -138,7 +122,7 @@ connection.read { transaction in let c: [Item] = transaction.readAtIndexes(indexes) let d: [Item] = transaction.readByKeys(keys) let all: [Item] = transaction.readAll() - let meta: [Item.MetadataType] = transaction.readMetadataAtIndexes(indexes) + let meta: [MetadataType] = transaction.readMetadataAtIndexes(indexes) } ``` @@ -166,10 +150,17 @@ Reading items from the database is a little different. ```swift // Read using a YapDB.Index. -if let item = Item.read(transaction).byIndex(index) { +if let item = Item.read(transaction).atIndex(index) { // etc - item is correct type, no casting required. } +// Read value and metadata using a YapDB.Index. +if let item: YapItem? = Item.read(transaction).withMetadataAtIndex(index) { + // etc - item is a correct type, no casting required. + // item.value contains the value + // item.metadata contains the metadata, wrapped in an Optional +} + // Read an array of items from an array of YapDB.Index(s) let items = Item.read(transaction).atIndexes(indexes) @@ -192,7 +183,7 @@ let (items, missingKeys) = Item.read(transaction).filterExisting(someKeys) Similarly, to work directly on a `YapDatabaseConnection`, use the following: ```swift -if let item = Item.read(connection).byIndex(index) { +if let item = Item.read(connection).atIndex(index) { // etc - item is correct type, no casting required. } @@ -233,6 +224,7 @@ To start working in this repository’s `YapDatabaseExtensions.xcodeproj`, you ## Author Daniel Thorpe, [@danthorpe](https://twitter.com/danthorpe) +Jim Roepcke, [@JimRoepcke](https://twitter.com/JimRoepcke) ## License From 31f0dcef8af0b614b18ccee27d7f6a2ef6c2c73a Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Wed, 28 Dec 2016 17:30:53 -0800 Subject: [PATCH 15/54] update credentials_manager to 0.16.4 (thanks for yanking gems, fastlane) --- Gemfile.lock | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b7cdf05..911cca6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -55,9 +55,9 @@ GEM netrc (= 0.7.8) cocoapods-try (1.1.0) colored (1.2) - commander (4.4.1) + commander (4.4.3) highline (~> 1.7.2) - credentials_manager (0.16.2) + credentials_manager (0.16.4) colored commander (>= 4.3.5) highline (>= 1.7.1) @@ -299,9 +299,10 @@ PLATFORMS DEPENDENCIES cocoapods cocoapods-keys + credentials_manager (= 0.16.4) fastlane slather xcpretty BUNDLED WITH - 1.13.6 + 1.13.7 From fcebdd4bfb7880c96c6f05ee68a52aba41168e6d Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Wed, 28 Dec 2016 17:31:11 -0800 Subject: [PATCH 16/54] update the podspec to fork the pod --- YapDatabaseExtensions.podspec | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/YapDatabaseExtensions.podspec b/YapDatabaseExtensions.podspec index c2da953..46c79fd 100644 --- a/YapDatabaseExtensions.podspec +++ b/YapDatabaseExtensions.podspec @@ -1,30 +1,30 @@ Pod::Spec.new do |s| - s.name = "YapDatabaseExtensions" - s.version = "2.6.0" + s.name = "RCSYapDatabaseExtensions" + s.version = "3.0.0" s.summary = "Helpers for using value types with YapDatabase." s.description = <<-DESC Defines APIs to conveniently read, write and remove objects and values to or from YapDatabse. See ValueCoding for value type support. + + Fork of danthorpe's YapDatabaseExtensions with Swift 3 support and + metadata separated from objects. DESC - s.homepage = "https://github.com/danthorpe/YapDatabaseExtensions" + s.homepage = "https://github.com/JimRoepcke/YapDatabaseExtensions" s.license = 'MIT' - s.author = { "Daniel Thorpe" => "@danthorpe" } - s.source = { :git => "https://github.com/danthorpe/YapDatabaseExtensions.git", :tag => s.version.to_s } - s.module_name = 'YapDatabaseExtensions' - s.social_media_url = 'https://twitter.com/danthorpe' + s.authors = { "Daniel Thorpe" => "@danthorpe", "Jim Roepcke" => "@JimRoepcke" } + s.source = { :git => "https://github.com/JimRoepcke/YapDatabaseExtensions.git", :tag => s.version.to_s } + s.module_name = 'RCSYapDatabaseExtensions' + s.social_media_url = 'https://twitter.com/JimRoepcke' s.requires_arc = true s.default_subspec = 'Persitable' - s.ios.deployment_target = '8.0' - s.osx.deployment_target = '10.10' + s.ios.deployment_target = '9.0' + s.osx.deployment_target = '10.11' - s.dependency 'ValueCoding', '~> 1.5' + s.dependency 'ValueCoding', '~> 2.1.0' s.dependency 'YapDatabase', '2.9.2' - # Ensure the correct version of Swift is used - s.pod_target_xcconfig = { 'SWIFT_VERSION' => '2.3' } - s.subspec 'Core' do |ss| ss.source_files = [ 'Sources/YapDatabaseExtensions.swift', From e1c674dd5a0f88c06d0831c681094f2c41d3cf9d Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 00:04:29 -0800 Subject: [PATCH 17/54] update Cartfile for Swift 3 --- Cartfile | 5 ++--- Cartfile.resolved | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Cartfile b/Cartfile index 034481a..00e0c1c 100644 --- a/Cartfile +++ b/Cartfile @@ -1,3 +1,2 @@ -github "danthorpe/ValueCoding" "1.5.0" -github "CocoaLumberjack/CocoaLumberjack" "2.4.0" -github "yapstudios/YapDatabase" "2.9.2" \ No newline at end of file +github "danthorpe/ValueCoding" "2.1.0" +github "yapstudios/YapDatabase" "2.9.3" \ No newline at end of file diff --git a/Cartfile.resolved b/Cartfile.resolved index 8ae8b91..f10e04c 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,4 +1,3 @@ -github "CocoaLumberjack/CocoaLumberjack" "2.4.0" -github "tonymillion/Reachability" "c4d225a479379f9998dbd5b55070427373d20574" -github "danthorpe/ValueCoding" "1.5.0" -github "yapstudios/YapDatabase" "2.9.2" +github "CocoaLumberjack/CocoaLumberjack" "3.0.0" +github "danthorpe/ValueCoding" "2.1.0" +github "yapstudios/YapDatabase" "2.9.3" From 73f70e227eabc674eb339b631fae1878340c2619 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 00:04:36 -0800 Subject: [PATCH 18/54] run the Swift 3 converter --- .../Curried_ObjectWithObjectMetadata.swift | 28 +- Sources/Curried_ObjectWithValueMetadata.swift | 28 +- Sources/Curried_ValueWithNoMetadata.swift | 28 +- Sources/Curried_ValueWithObjectMetadata.swift | 30 +- Sources/Curried_ValueWithValueMetadata.swift | 30 +- .../Functional_AnyWithObjectMetadata.swift | 20 +- Sources/Functional_AnyWithValueMetadata.swift | 26 +- Sources/Functional_ObjectWithNoMetadata.swift | 94 +++---- .../Functional_ObjectWithObjectMetadata.swift | 92 +++---- .../Functional_ObjectWithValueMetadata.swift | 92 +++---- Sources/Functional_Remove.swift | 30 +- .../Functional_ValueWIthObjectMetadata.swift | 124 ++++----- .../Functional_ValueWIthValueMetadata.swift | 124 ++++----- Sources/Functional_ValueWithNoMetadata.swift | 94 +++---- .../Persistable_AnyWithObjectMetadata.swift | 26 +- .../Persistable_AnyWithValueMetadata.swift | 32 +-- ...Persistable_ObjectWithObjectMetadata.swift | 94 +++---- .../Persistable_ObjectWithValueMetadata.swift | 120 ++++---- Sources/Persistable_Remove.swift | 24 +- Sources/Persistable_ValueWithNoMetadata.swift | 72 ++--- .../Persistable_ValueWithObjectMetadata.swift | 102 +++---- .../Persistable_ValueWithValueMetadata.swift | 128 ++++----- Sources/Read.swift | 24 +- Sources/YapDB.swift | 258 +++++++++--------- Sources/YapDatabaseExtensions.swift | 132 ++++----- Tests/Models.swift | 132 ++++----- Tests/ObjectWithNoMetadataTests.swift | 64 ++--- Tests/ObjectWithObjectMetadataTests.swift | 84 +++--- Tests/ObjectWithValueMetadataTests.swift | 72 ++--- Tests/ReadWriteTests.swift | 14 +- Tests/Support.swift | 36 +-- Tests/ValueWithNoMetadataTests.swift | 72 ++--- Tests/ValueWithObjectMetadataTests.swift | 84 +++--- Tests/ValueWithValueMetadataTests.swift | 76 +++--- Tests/YapDatabaseExtensionsTests.swift | 24 +- .../project.pbxproj | 12 +- 36 files changed, 1261 insertions(+), 1261 deletions(-) diff --git a/Sources/Curried_ObjectWithObjectMetadata.swift b/Sources/Curried_ObjectWithObjectMetadata.swift index 77587cb..3fe8990 100644 --- a/Sources/Curried_ObjectWithObjectMetadata.swift +++ b/Sources/Curried_ObjectWithObjectMetadata.swift @@ -22,9 +22,9 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readWithMetadataAtIndex< - ReadTransaction, Metadata where + ReadTransaction, Metadata>(_ index: YapDB.Index) -> (ReadTransaction) -> YapItem? where ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(index: YapDB.Index) -> ReadTransaction -> YapItem? { + Metadata: NSCoding { return { $0.readWithMetadataAtIndex(index) } } @@ -36,11 +36,11 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataAtIndexes< - Indexes, ReadTransaction, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, ReadTransaction, Metadata>(_ indexes: Indexes) -> (ReadTransaction) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(indexes: Indexes) -> ReadTransaction -> [YapItem] { + Metadata: NSCoding { return { $0.readWithMetadataAtIndexes(indexes) } } @@ -52,9 +52,9 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readWithMetadataByKey< - ReadTransaction, Metadata where + ReadTransaction, Metadata>(_ key: String) -> (ReadTransaction) -> YapItem? where ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(key: String) -> ReadTransaction -> YapItem? { + Metadata: NSCoding { return { $0.readWithMetadataByKey(key) } } @@ -66,11 +66,11 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataByKeys< - Keys, ReadTransaction, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, ReadTransaction, Metadata>(_ keys: Keys) -> (ReadTransaction) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(keys: Keys) -> ReadTransaction -> [YapItem] { + Metadata: NSCoding { return { $0.readWithMetadataAtIndexes(Self.indexesWithKeys(keys)) } } @@ -82,9 +82,9 @@ extension Persistable where - returns: a (WriteTransaction) -> Self closure */ public func writeWithMetadata< - WriteTransaction, Metadata where + WriteTransaction, Metadata>(_ metadata: Metadata? = nil) -> (WriteTransaction) -> YapItem where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(metadata: Metadata? = nil) -> WriteTransaction -> YapItem { + Metadata: NSCoding { return { $0.writeWithMetadata(YapItem(self, metadata)) } } } diff --git a/Sources/Curried_ObjectWithValueMetadata.swift b/Sources/Curried_ObjectWithValueMetadata.swift index 9dd1702..a726ea5 100644 --- a/Sources/Curried_ObjectWithValueMetadata.swift +++ b/Sources/Curried_ObjectWithValueMetadata.swift @@ -22,11 +22,11 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readWithMetadataAtIndex< - ReadTransaction, Metadata where + ReadTransaction, Metadata>(_ index: YapDB.Index) -> (ReadTransaction) -> YapItem? where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> ReadTransaction -> YapItem? { + Metadata.Coder.Value == Metadata { return { $0.readWithMetadataAtIndex(index) } } @@ -38,13 +38,13 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataAtIndexes< - Indexes, ReadTransaction, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, ReadTransaction, Metadata>(_ indexes: Indexes) -> (ReadTransaction) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> ReadTransaction -> [YapItem] { + Metadata.Coder.Value == Metadata { return { $0.readWithMetadataAtIndexes(indexes) } } @@ -56,11 +56,11 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readWithMetadataByKey< - ReadTransaction, Metadata where + ReadTransaction, Metadata>(_ key: String) -> (ReadTransaction) -> YapItem? where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> ReadTransaction -> YapItem? { + Metadata.Coder.Value == Metadata { return { $0.readWithMetadataByKey(key) } } @@ -72,13 +72,13 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataByKeys< - Keys, ReadTransaction, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, ReadTransaction, Metadata>(_ keys: Keys) -> (ReadTransaction) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> ReadTransaction -> [YapItem] { + Metadata.Coder.Value == Metadata { return { $0.readWithMetadataAtIndexes(Self.indexesWithKeys(keys)) } } @@ -90,11 +90,11 @@ extension Persistable where - returns: a (WriteTransaction) -> Self closure */ public func writeWithMetadata< - WriteTransaction, Metadata where + WriteTransaction, Metadata>(_ metadata: Metadata? = nil) -> (WriteTransaction) -> YapItem where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(metadata: Metadata? = nil) -> WriteTransaction -> YapItem { + Metadata.Coder.Value == Metadata { return { $0.writeWithMetadata(YapItem(self, metadata)) } } } diff --git a/Sources/Curried_ValueWithNoMetadata.swift b/Sources/Curried_ValueWithNoMetadata.swift index 60cd00a..01ea119 100644 --- a/Sources/Curried_ValueWithNoMetadata.swift +++ b/Sources/Curried_ValueWithNoMetadata.swift @@ -14,7 +14,7 @@ import ValueCoding extension Persistable where Self: ValueCoding, Self.Coder: NSCoding, - Self.Coder.ValueType == Self { + Self.Coder.Value == Self { /** Returns a closure which, given a read transaction will return @@ -24,8 +24,8 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readAtIndex< - ReadTransaction where - ReadTransaction: ReadTransactionType>(index: YapDB.Index) -> ReadTransaction -> Self? { + ReadTransaction>(_ index: YapDB.Index) -> (ReadTransaction) -> Self? where + ReadTransaction: ReadTransactionType { return { $0.readAtIndex(index) } } @@ -37,10 +37,10 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readAtIndexes< - Indexes, ReadTransaction where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, - ReadTransaction: ReadTransactionType>(indexes: Indexes) -> ReadTransaction -> [Self] { + Indexes, ReadTransaction>(_ indexes: Indexes) -> (ReadTransaction) -> [Self] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, + ReadTransaction: ReadTransactionType { return { $0.readAtIndexes(indexes) } } @@ -52,8 +52,8 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readByKey< - ReadTransaction where - ReadTransaction: ReadTransactionType>(key: String) -> ReadTransaction -> Self? { + ReadTransaction>(_ key: String) -> (ReadTransaction) -> Self? where + ReadTransaction: ReadTransactionType { return { $0.readByKey(key) } } @@ -65,10 +65,10 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readByKeys< - Keys, ReadTransaction where - Keys: SequenceType, - Keys.Generator.Element == String, - ReadTransaction: ReadTransactionType>(keys: Keys) -> ReadTransaction -> [Self] { + Keys, ReadTransaction>(_ keys: Keys) -> (ReadTransaction) -> [Self] where + Keys: Sequence, + Keys.Iterator.Element == String, + ReadTransaction: ReadTransactionType { return { $0.readAtIndexes(Self.indexesWithKeys(keys)) } } @@ -79,7 +79,7 @@ extension Persistable where - warning: Be aware that this will capure `self`. - returns: a (WriteTransaction) -> Self closure */ - public func write() -> WriteTransaction -> Self { + public func write() -> (WriteTransaction) -> Self { return { $0.write(self) } } } diff --git a/Sources/Curried_ValueWithObjectMetadata.swift b/Sources/Curried_ValueWithObjectMetadata.swift index 6ff0779..8b31bc0 100644 --- a/Sources/Curried_ValueWithObjectMetadata.swift +++ b/Sources/Curried_ValueWithObjectMetadata.swift @@ -14,7 +14,7 @@ import ValueCoding extension Persistable where Self: ValueCoding, Self.Coder: NSCoding, - Self.Coder.ValueType == Self { + Self.Coder.Value == Self { /** Returns a closure which, given a read transaction will return @@ -24,9 +24,9 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readWithMetadataAtIndex< - ReadTransaction, Metadata where + ReadTransaction, Metadata>(_ index: YapDB.Index) -> (ReadTransaction) -> YapItem? where ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(index: YapDB.Index) -> ReadTransaction -> YapItem? { + Metadata: NSCoding { return { $0.readWithMetadataAtIndex(index) } } @@ -38,11 +38,11 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataAtIndexes< - Indexes, ReadTransaction, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, ReadTransaction, Metadata>(_ indexes: Indexes) -> (ReadTransaction) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(indexes: Indexes) -> ReadTransaction -> [YapItem] { + Metadata: NSCoding { return { $0.readWithMetadataAtIndexes(indexes) } } @@ -54,9 +54,9 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readWithMetadataByKey< - ReadTransaction, Metadata where + ReadTransaction, Metadata>(_ key: String) -> (ReadTransaction) -> YapItem? where ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(key: String) -> ReadTransaction -> YapItem? { + Metadata: NSCoding { return { $0.readWithMetadataByKey(key) } } @@ -68,11 +68,11 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataByKeys< - Keys, ReadTransaction, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, ReadTransaction, Metadata>(_ keys: Keys) -> (ReadTransaction) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, ReadTransaction: ReadTransactionType, - Metadata: NSCoding>(keys: Keys) -> ReadTransaction -> [YapItem] { + Metadata: NSCoding { return { $0.readWithMetadataAtIndexes(Self.indexesWithKeys(keys)) } } @@ -84,9 +84,9 @@ extension Persistable where - returns: a (WriteTransaction) -> Self closure */ public func writeWithMetadata< - WriteTransaction, Metadata where + WriteTransaction, Metadata>(_ metadata: Metadata? = nil) -> (WriteTransaction) -> YapItem where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(metadata: Metadata? = nil) -> WriteTransaction -> YapItem { + Metadata: NSCoding { return { $0.writeWithMetadata(YapItem(self, metadata)) } } } diff --git a/Sources/Curried_ValueWithValueMetadata.swift b/Sources/Curried_ValueWithValueMetadata.swift index 4525175..07ddb55 100644 --- a/Sources/Curried_ValueWithValueMetadata.swift +++ b/Sources/Curried_ValueWithValueMetadata.swift @@ -14,7 +14,7 @@ import ValueCoding extension Persistable where Self: ValueCoding, Self.Coder: NSCoding, - Self.Coder.ValueType == Self { + Self.Coder.Value == Self { /** Returns a closure which, given a read transaction will return @@ -24,11 +24,11 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readWithMetadataAtIndex< - ReadTransaction, Metadata where + ReadTransaction, Metadata>(_ index: YapDB.Index) -> (ReadTransaction) -> YapItem? where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> ReadTransaction -> YapItem? { + Metadata.Coder.Value == Metadata { return { $0.readWithMetadataAtIndex(index) } } @@ -40,13 +40,13 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataAtIndexes< - Indexes, ReadTransaction, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, ReadTransaction, Metadata>(_ indexes: Indexes) -> (ReadTransaction) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> ReadTransaction -> [YapItem] { + Metadata.Coder.Value == Metadata { return { $0.readWithMetadataAtIndexes(indexes) } } @@ -58,11 +58,11 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readWithMetadataByKey< - ReadTransaction, Metadata where + ReadTransaction, Metadata>(_ key: String) -> (ReadTransaction) -> YapItem? where ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> ReadTransaction -> YapItem? { + Metadata.Coder.Value == Metadata { return { $0.readWithMetadataByKey(key) } } @@ -74,13 +74,13 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataByKeys< - Keys, ReadTransaction, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, ReadTransaction, Metadata>(_ keys: Keys) -> (ReadTransaction) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, ReadTransaction: ReadTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> ReadTransaction -> [YapItem] { + Metadata.Coder.Value == Metadata { return { $0.readWithMetadataAtIndexes(Self.indexesWithKeys(keys)) } } @@ -92,11 +92,11 @@ extension Persistable where - returns: a (WriteTransaction) -> Self closure */ public func writeWithMetadata< - WriteTransaction, Metadata where + WriteTransaction, Metadata>(_ metadata: Metadata? = nil) -> (WriteTransaction) -> YapItem where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(metadata: Metadata? = nil) -> WriteTransaction -> YapItem { + Metadata.Coder.Value == Metadata { return { $0.writeWithMetadata(YapItem(self, metadata)) } } } diff --git a/Sources/Functional_AnyWithObjectMetadata.swift b/Sources/Functional_AnyWithObjectMetadata.swift index 1b905b4..a68609d 100644 --- a/Sources/Functional_AnyWithObjectMetadata.swift +++ b/Sources/Functional_AnyWithObjectMetadata.swift @@ -21,7 +21,7 @@ extension ReadTransactionType { - returns: an optional `MetadataType` */ public func readMetadataAtIndex< - MetadataType: NSCoding>(index: YapDB.Index) -> MetadataType? { + MetadataType: NSCoding>(_ index: YapDB.Index) -> MetadataType? { return readMetadataAtIndex(index) as? MetadataType } @@ -32,10 +32,10 @@ extension ReadTransactionType { - returns: an array of `MetadataType` */ public func readMetadataAtIndexes< - Indexes, MetadataType where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, - MetadataType: NSCoding>(indexes: Indexes) -> [MetadataType] { + Indexes, MetadataType>(_ indexes: Indexes) -> [MetadataType] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, + MetadataType: NSCoding { return indexes.flatMap(readMetadataAtIndex) } } @@ -49,7 +49,7 @@ extension ConnectionType { - returns: an optional `MetadataType` */ public func readMetadataAtIndex< - MetadataType: NSCoding>(index: YapDB.Index) -> MetadataType? { + MetadataType: NSCoding>(_ index: YapDB.Index) -> MetadataType? { return read { $0.readMetadataAtIndex(index) } } @@ -60,10 +60,10 @@ extension ConnectionType { - returns: an array of `MetadataType` */ public func readMetadataAtIndexes< - Indexes, MetadataType where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, - MetadataType: NSCoding>(indexes: Indexes) -> [MetadataType] { + Indexes, MetadataType>(_ indexes: Indexes) -> [MetadataType] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, + MetadataType: NSCoding { return read { $0.readMetadataAtIndexes(indexes) } } } diff --git a/Sources/Functional_AnyWithValueMetadata.swift b/Sources/Functional_AnyWithValueMetadata.swift index 1e91339..0f4890f 100644 --- a/Sources/Functional_AnyWithValueMetadata.swift +++ b/Sources/Functional_AnyWithValueMetadata.swift @@ -21,11 +21,11 @@ extension ReadTransactionType { - returns: an optional `MetadataType` */ public func readMetadataAtIndex< - MetadataType where + MetadataType>(_ index: YapDB.Index) -> MetadataType? where MetadataType: ValueCoding, MetadataType.Coder: NSCoding, - MetadataType.Coder.ValueType == MetadataType>(index: YapDB.Index) -> MetadataType? { - return MetadataType.decode(readMetadataAtIndex(index)) + MetadataType.Coder.Value == MetadataType { + return MetadataType.decode(readMetadataAtIndex(index) as Any?) } /** @@ -35,12 +35,12 @@ extension ReadTransactionType { - returns: an array of `MetadataType` */ public func readMetadataAtIndexes< - Indexes, MetadataType where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, MetadataType>(_ indexes: Indexes) -> [MetadataType] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, MetadataType: ValueCoding, MetadataType.Coder: NSCoding, - MetadataType.Coder.ValueType == MetadataType>(indexes: Indexes) -> [MetadataType] { + MetadataType.Coder.Value == MetadataType { return indexes.flatMap(readMetadataAtIndex) } } @@ -54,10 +54,10 @@ extension ConnectionType { - returns: an optional `MetadataType` */ public func readMetadataAtIndex< - MetadataType where + MetadataType>(_ index: YapDB.Index) -> MetadataType? where MetadataType: ValueCoding, MetadataType.Coder: NSCoding, - MetadataType.Coder.ValueType == MetadataType>(index: YapDB.Index) -> MetadataType? { + MetadataType.Coder.Value == MetadataType { return read { $0.readMetadataAtIndex(index) } } @@ -68,12 +68,12 @@ extension ConnectionType { - returns: an array of `MetadataType` */ public func readMetadataAtIndexes< - Indexes, MetadataType where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, MetadataType>(_ indexes: Indexes) -> [MetadataType] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, MetadataType: ValueCoding, MetadataType.Coder: NSCoding, - MetadataType.Coder.ValueType == MetadataType>(indexes: Indexes) -> [MetadataType] { + MetadataType.Coder.Value == MetadataType { return read { $0.readMetadataAtIndexes(indexes) } } } diff --git a/Sources/Functional_ObjectWithNoMetadata.swift b/Sources/Functional_ObjectWithNoMetadata.swift index 6cebd10..251bab3 100644 --- a/Sources/Functional_ObjectWithNoMetadata.swift +++ b/Sources/Functional_ObjectWithNoMetadata.swift @@ -21,9 +21,9 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readAtIndex< - Object where + Object>(_ index: YapDB.Index) -> Object? where Object: Persistable, - Object: NSCoding>(index: YapDB.Index) -> Object? { + Object: NSCoding { return readAtIndex(index) as? Object } @@ -34,11 +34,11 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, Object where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Object>(_ indexes: Indexes) -> [Object] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Object: Persistable, - Object: NSCoding>(indexes: Indexes) -> [Object] { + Object: NSCoding { return indexes.flatMap(readAtIndex) } @@ -49,9 +49,9 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readByKey< - Object where + Object>(_ key: String) -> Object? where Object: Persistable, - Object: NSCoding>(key: String) -> Object? { + Object: NSCoding { return readAtIndex(Object.indexWithKey(key)) } @@ -62,11 +62,11 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, Object where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Object>(_ keys: Keys) -> [Object] where + Keys: Sequence, + Keys.Iterator.Element == String, Object: Persistable, - Object: NSCoding>(keys: Keys) -> [Object] { + Object: NSCoding { return readAtIndexes(Object.indexesWithKeys(keys)) } @@ -76,9 +76,9 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAll< - Object where + Object>() -> [Object] where Object: Persistable, - Object: NSCoding>() -> [Object] { + Object: NSCoding { return readByKeys(keysInCollection(Object.collection)) } } @@ -92,9 +92,9 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readAtIndex< - Object where + Object>(_ index: YapDB.Index) -> Object? where Object: Persistable, - Object: NSCoding>(index: YapDB.Index) -> Object? { + Object: NSCoding { return read { $0.readAtIndex(index) } } @@ -105,11 +105,11 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, Object where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Object>(_ indexes: Indexes) -> [Object] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Object: Persistable, - Object: NSCoding>(indexes: Indexes) -> [Object] { + Object: NSCoding { return read { $0.readAtIndexes(indexes) } } @@ -120,9 +120,9 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readByKey< - Object where + Object>(_ key: String) -> Object? where Object: Persistable, - Object: NSCoding>(key: String) -> Object? { + Object: NSCoding { return readAtIndex(Object.indexWithKey(key)) } @@ -133,11 +133,11 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, Object where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Object>(_ keys: Keys) -> [Object] where + Keys: Sequence, + Keys.Iterator.Element == String, Object: Persistable, - Object: NSCoding>(keys: Keys) -> [Object] { + Object: NSCoding { return readAtIndexes(Object.indexesWithKeys(keys)) } @@ -147,9 +147,9 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAll< - Object where + Object>() -> [Object] where Object: Persistable, - Object: NSCoding>() -> [Object] { + Object: NSCoding { return read { $0.readAll() } } } @@ -165,10 +165,10 @@ extension WriteTransactionType { - returns: the same item */ public func write< - Object where + Object>(_ item: Object) -> Object where Object: Persistable, - Object: NSCoding>(item: Object) -> Object { - writeAtIndex(item.index, object: item, metadata: .None) + Object: NSCoding { + writeAtIndex(item.index, object: item, metadata: .none) return item } @@ -179,11 +179,11 @@ extension WriteTransactionType { - returns: the same items, in an array. */ public func write< - Items, Object where - Items: SequenceType, - Items.Generator.Element == Object, + Items, Object>(_ items: Items) -> [Object] where + Items: Sequence, + Items.Iterator.Element == Object, Object: Persistable, - Object: NSCoding>(items: Items) -> [Object] { + Object: NSCoding { return items.map(write) } } @@ -197,9 +197,9 @@ extension ConnectionType { - returns: the same item */ public func write< - Object where + Object>(_ item: Object) -> Object where Object: Persistable, - Object: NSCoding>(item: Object) -> Object { + Object: NSCoding { return write { $0.write(item) } } @@ -210,11 +210,11 @@ extension ConnectionType { - returns: the same items, in an array. */ public func write< - Items, Object where - Items: SequenceType, - Items.Generator.Element == Object, + Items, Object>(_ items: Items) -> [Object] where + Items: Sequence, + Items.Iterator.Element == Object, Object: Persistable, - Object: NSCoding>(items: Items) -> [Object] { + Object: NSCoding { return write { $0.write(items) } } @@ -226,9 +226,9 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - Object where + Object>(_ item: Object, queue: DispatchQueue = DispatchQueue.main, completion: ((Object) -> Void)? = .none) where Object: Persistable, - Object: NSCoding>(item: Object, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (Object -> Void)? = .None) { + Object: NSCoding { asyncWrite({ $0.write(item) }, queue: queue, completion: completion) } @@ -240,11 +240,11 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - Items, Object where - Items: SequenceType, - Items.Generator.Element == Object, + Items, Object>(_ items: Items, queue: DispatchQueue = DispatchQueue.main, completion: (([Object]) -> Void)? = .none) where + Items: Sequence, + Items.Iterator.Element == Object, Object: Persistable, - Object: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([Object] -> Void)? = .None) { + Object: NSCoding { asyncWrite({ $0.write(items) }, queue: queue, completion: completion) } } diff --git a/Sources/Functional_ObjectWithObjectMetadata.swift b/Sources/Functional_ObjectWithObjectMetadata.swift index 3a9d98d..d581974 100644 --- a/Sources/Functional_ObjectWithObjectMetadata.swift +++ b/Sources/Functional_ObjectWithObjectMetadata.swift @@ -21,10 +21,10 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readWithMetadataAtIndex< - Object, Metadata where + Object, Metadata>(_ index: YapDB.Index) -> YapItem? where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(index: YapDB.Index) -> YapItem? { + Metadata: NSCoding { guard let item: Object = readAtIndex(index) else { return nil } let metadata: Metadata? = readMetadataAtIndex(index) return YapItem(item, metadata) @@ -37,12 +37,12 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Object, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Object, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(indexes: Indexes) -> [YapItem] { + Metadata: NSCoding { // FIXME: using flatMap means the output length need not match the input length return indexes.flatMap(readWithMetadataAtIndex) } @@ -54,10 +54,10 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readWithMetadataByKey< - Object, Metadata where + Object, Metadata>(_ key: String) -> YapItem? where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(key: String) -> YapItem? { + Metadata: NSCoding { return readWithMetadataAtIndex(Object.indexWithKey(key)) } @@ -68,12 +68,12 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Object, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Object, Metadata>(_ keys: Keys) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(keys: Keys) -> [YapItem] { + Metadata: NSCoding { return readWithMetadataAtIndexes(Object.indexesWithKeys(keys)) } @@ -83,10 +83,10 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Object, Metadata where + Object, Metadata>() -> [YapItem] where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>() -> [YapItem] { + Metadata: NSCoding { return readWithMetadataByKeys(keysInCollection(Object.collection)) } } @@ -100,10 +100,10 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readWithMetadataAtIndex< - Object, Metadata where + Object, Metadata>(_ index: YapDB.Index) -> YapItem? where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(index: YapDB.Index) -> YapItem? { + Metadata: NSCoding { return read { $0.readWithMetadataAtIndex(index) } } @@ -114,12 +114,12 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Object, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Object, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(indexes: Indexes) -> [YapItem] { + Metadata: NSCoding { return read { $0.readWithMetadataAtIndexes(indexes) } } @@ -130,10 +130,10 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readWithMetadataByKey< - Object, Metadata where + Object, Metadata>(_ key: String) -> YapItem? where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(key: String) -> YapItem? { + Metadata: NSCoding { return readWithMetadataAtIndex(Object.indexWithKey(key)) } @@ -144,12 +144,12 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Object, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Object, Metadata>(_ keys: Keys) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(keys: Keys) -> [YapItem] { + Metadata: NSCoding { return readWithMetadataAtIndexes(Object.indexesWithKeys(keys)) } @@ -159,10 +159,10 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Object, Metadata where + Object, Metadata>() -> [YapItem] where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>() -> [YapItem] { + Metadata: NSCoding { return read { $0.readWithMetadataAll() } } } @@ -177,10 +177,10 @@ extension WriteTransactionType { - parameter item: the item to store. */ public func writeWithMetadata< - Object, Metadata where + Object, Metadata>(_ item: YapItem) -> YapItem where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(item: YapItem) -> YapItem { + Metadata: NSCoding { writeAtIndex(item.value.index, object: item.value, metadata: item.metadata) return item } @@ -191,12 +191,12 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ public func writeWithMetadata< - Items, Object, Metadata where - Items: SequenceType, - Items.Generator.Element == YapItem, + Items, Object, Metadata>(_ items: Items) -> [YapItem] where + Items: Sequence, + Items.Iterator.Element == YapItem, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(items: Items) -> [YapItem] { + Metadata: NSCoding { return items.map(writeWithMetadata) } } @@ -209,10 +209,10 @@ extension ConnectionType { - parameter item: the item to store. */ public func writeWithMetadata< - Object, Metadata where + Object, Metadata>(_ item: YapItem) -> YapItem where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(item: YapItem) -> YapItem { + Metadata: NSCoding { return write { $0.writeWithMetadata(item) } } @@ -222,12 +222,12 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ public func writeWithMetadata< - Items, Object, Metadata where - Items: SequenceType, - Items.Generator.Element == YapItem, + Items, Object, Metadata>(_ items: Items) -> [YapItem] where + Items: Sequence, + Items.Iterator.Element == YapItem, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(items: Items) -> [YapItem] { + Metadata: NSCoding { return write { $0.writeWithMetadata(items) } } @@ -239,10 +239,10 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWriteWithMetadata< - Object, Metadata where + Object, Metadata>(_ item: YapItem, queue: DispatchQueue = DispatchQueue.main, completion: ((YapItem) -> Void)? = .none) where Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(item: YapItem, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { + Metadata: NSCoding { asyncWrite({ $0.writeWithMetadata(item) }, queue: queue, completion: completion) } @@ -254,12 +254,12 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWriteWithMetadata< - Items, Object, Metadata where - Items: SequenceType, - Items.Generator.Element == YapItem, + Items, Object, Metadata>(_ items: Items, queue: DispatchQueue = DispatchQueue.main, completion: (([YapItem]) -> Void)? = .none) where + Items: Sequence, + Items.Iterator.Element == YapItem, Object: Persistable, Object: NSCoding, - Metadata: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { + Metadata: NSCoding { asyncWrite({ $0.writeWithMetadata(items) }, queue: queue, completion: completion) } } diff --git a/Sources/Functional_ObjectWithValueMetadata.swift b/Sources/Functional_ObjectWithValueMetadata.swift index ca78eb5..7bb30f0 100644 --- a/Sources/Functional_ObjectWithValueMetadata.swift +++ b/Sources/Functional_ObjectWithValueMetadata.swift @@ -21,12 +21,12 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readWithMetadataAtIndex< - Object, Metadata where + Object, Metadata>(_ index: YapDB.Index) -> YapItem? where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> YapItem? { + Metadata.Coder.Value == Metadata { guard let item: Object = readAtIndex(index) else { return nil } let metadata: Metadata? = readMetadataAtIndex(index) return YapItem(item, metadata) @@ -39,14 +39,14 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Object, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Object, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [YapItem] { + Metadata.Coder.Value == Metadata { // FIXME: using flatMap means the output length need not match the input length return indexes.flatMap(readWithMetadataAtIndex) } @@ -58,12 +58,12 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readWithMetadataByKey< - Object, Metadata where + Object, Metadata>(_ key: String) -> YapItem? where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> YapItem? { + Metadata.Coder.Value == Metadata { return readWithMetadataAtIndex(Object.indexWithKey(key)) } @@ -74,14 +74,14 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Object, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Object, Metadata>(_ keys: Keys) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [YapItem] { + Metadata.Coder.Value == Metadata { return readWithMetadataAtIndexes(Object.indexesWithKeys(keys)) } @@ -91,12 +91,12 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Object, Metadata where + Object, Metadata>() -> [YapItem] where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>() -> [YapItem] { + Metadata.Coder.Value == Metadata { return readWithMetadataByKeys(keysInCollection(Object.collection)) } } @@ -110,12 +110,12 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readWithMetadataAtIndex< - Object, Metadata where + Object, Metadata>(_ index: YapDB.Index) -> YapItem? where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> YapItem? { + Metadata.Coder.Value == Metadata { return read { $0.readWithMetadataAtIndex(index) } } @@ -126,14 +126,14 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Object, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Object, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [YapItem] { + Metadata.Coder.Value == Metadata { return read { $0.readWithMetadataAtIndexes(indexes) } } @@ -144,12 +144,12 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readWithMetadataByKey< - Object, Metadata where + Object, Metadata>(_ key: String) -> YapItem? where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> YapItem? { + Metadata.Coder.Value == Metadata { return readWithMetadataAtIndex(Object.indexWithKey(key)) } @@ -160,14 +160,14 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Object, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Object, Metadata>(_ keys: Keys) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [YapItem] { + Metadata.Coder.Value == Metadata { return readWithMetadataAtIndexes(Object.indexesWithKeys(keys)) } @@ -177,12 +177,12 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Object, Metadata where + Object, Metadata>() -> [YapItem] where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>() -> [YapItem] { + Metadata.Coder.Value == Metadata { return read { $0.readWithMetadataAll() } } } @@ -197,12 +197,12 @@ extension WriteTransactionType { - parameter item: the item to store. */ public func writeWithMetadata< - Object, Metadata where + Object, Metadata>(_ item: YapItem) -> YapItem where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(item: YapItem) -> YapItem { + Metadata.Coder.Value == Metadata { writeAtIndex(item.value.index, object: item.value, metadata: item.metadata?.encoded) return item } @@ -213,14 +213,14 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ public func writeWithMetadata< - Items, Object, Metadata where - Items: SequenceType, - Items.Generator.Element == YapItem, + Items, Object, Metadata>(_ items: Items) -> [YapItem] where + Items: Sequence, + Items.Iterator.Element == YapItem, Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(items: Items) -> [YapItem] { + Metadata.Coder.Value == Metadata { return items.map(writeWithMetadata) } } @@ -233,12 +233,12 @@ extension ConnectionType { - parameter item: the item to store. */ public func writeWithMetadata< - Object, Metadata where + Object, Metadata>(_ item: YapItem) -> YapItem where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(item: YapItem) -> YapItem { + Metadata.Coder.Value == Metadata { return write { $0.writeWithMetadata(item) } } @@ -248,14 +248,14 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ public func writeWithMetadata< - Items, Object, Metadata where - Items: SequenceType, - Items.Generator.Element == YapItem, + Items, Object, Metadata>(_ items: Items) -> [YapItem] where + Items: Sequence, + Items.Iterator.Element == YapItem, Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(items: Items) -> [YapItem] { + Metadata.Coder.Value == Metadata { return write { $0.writeWithMetadata(items) } } @@ -267,12 +267,12 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWriteWithMetadata< - Object, Metadata where + Object, Metadata>(_ item: YapItem, queue: DispatchQueue = DispatchQueue.main, completion: ((YapItem) -> Void)? = .none) where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(item: YapItem, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { + Metadata.Coder.Value == Metadata { asyncWrite({ $0.writeWithMetadata(item) }, queue: queue, completion: completion) } @@ -284,14 +284,14 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWriteWithMetadata< - Items, Object, Metadata where - Items: SequenceType, - Items.Generator.Element == YapItem, + Items, Object, Metadata>(_ items: Items, queue: DispatchQueue = DispatchQueue.main, completion: (([YapItem]) -> Void)? = .none) where + Items: Sequence, + Items.Iterator.Element == YapItem, Object: Persistable, Object: NSCoding, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { + Metadata.Coder.Value == Metadata { asyncWrite({ $0.writeWithMetadata(items) }, queue: queue, completion: completion) } } diff --git a/Sources/Functional_Remove.swift b/Sources/Functional_Remove.swift index b45fc28..306cdac 100644 --- a/Sources/Functional_Remove.swift +++ b/Sources/Functional_Remove.swift @@ -15,7 +15,7 @@ extension WriteTransactionType { - parameter item: a `Persistable` item */ - public func remove(item: Item) { + public func remove(_ item: Item) { removeAtIndexes([item.index]) } @@ -25,10 +25,10 @@ extension WriteTransactionType { - parameter items: a sequence of `Persistable` items */ public func remove< - Items, Item where - Items: SequenceType, - Items.Generator.Element == Item, - Item: Persistable>(items: Items) { + Items, Item>(_ items: Items) where + Items: Sequence, + Items.Iterator.Element == Item, + Item: Persistable { removeAtIndexes(items.map { $0.index }) } } @@ -41,7 +41,7 @@ extension ConnectionType { - parameter item: a `Persistable` item */ - public func remove(item: Item) { + public func remove(_ item: Item) { write { $0.remove(item) } } @@ -52,10 +52,10 @@ extension ConnectionType { - parameter items: a sequence of `Persistable` items */ public func remove< - Items, Item where - Items: SequenceType, - Items.Generator.Element == Item, - Item: Persistable>(items: Items) { + Items, Item>(_ items: Items) where + Items: Sequence, + Items.Iterator.Element == Item, + Item: Persistable { write { $0.remove(items) } } @@ -65,7 +65,7 @@ extension ConnectionType { - parameter item: a `Persistable` item */ - public func asyncRemove(item: Item, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: dispatch_block_t? = .None) { + public func asyncRemove(_ item: Item, queue: DispatchQueue = DispatchQueue.main, completion: @escaping ()->()? = .none) { asyncWrite({ $0.remove(item) }, queue: queue, completion: { _ in completion?() }) } @@ -76,10 +76,10 @@ extension ConnectionType { - parameter items: a sequence of `Persistable` items */ public func asyncRemove< - Items, Item where - Items: SequenceType, - Items.Generator.Element == Item, - Item: Persistable>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: dispatch_block_t? = .None) { + Items, Item>(_ items: Items, queue: DispatchQueue = DispatchQueue.main, completion: @escaping ()->()? = .none) where + Items: Sequence, + Items.Iterator.Element == Item, + Item: Persistable { asyncWrite({ $0.remove(items) }, queue: queue, completion: { _ in completion?() }) } } diff --git a/Sources/Functional_ValueWIthObjectMetadata.swift b/Sources/Functional_ValueWIthObjectMetadata.swift index ce9f5b8..c19151e 100644 --- a/Sources/Functional_ValueWIthObjectMetadata.swift +++ b/Sources/Functional_ValueWIthObjectMetadata.swift @@ -21,12 +21,12 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readWithMetadataAtIndex< - Value, Metadata where + Value, Metadata>(_ index: YapDB.Index) -> YapItem? where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(index: YapDB.Index) -> YapItem? { + Value.Coder.Value == Value, + Metadata: NSCoding { guard let item: Value = Value.decode(readAtIndex(index)) else { return nil } let metadata: Metadata? = readMetadataAtIndex(index) return YapItem(item, metadata) @@ -39,14 +39,14 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Value, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Value, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(indexes: Indexes) -> [YapItem] { + Value.Coder.Value == Value, + Metadata: NSCoding { // FIXME: using flatMap means the output length need not match the input length return indexes.flatMap(readWithMetadataAtIndex) } @@ -58,12 +58,12 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readWithMetadataByKey< - Value, Metadata where + Value, Metadata>(_ key: String) -> YapItem? where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(key: String) -> YapItem? { + Value.Coder.Value == Value, + Metadata: NSCoding { return readWithMetadataAtIndex(Value.indexWithKey(key)) } @@ -74,14 +74,14 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Value, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Value, Metadata>(_ keys: Keys) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(keys: Keys) -> [YapItem] { + Value.Coder.Value == Value, + Metadata: NSCoding { return readWithMetadataAtIndexes(Value.indexesWithKeys(keys)) } @@ -91,12 +91,12 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Value, Metadata where + Value, Metadata>() -> [YapItem] where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>() -> [YapItem] { + Value.Coder.Value == Value, + Metadata: NSCoding { return readWithMetadataByKeys(keysInCollection(Value.collection)) } } @@ -110,12 +110,12 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readWithMetadataAtIndex< - Value, Metadata where + Value, Metadata>(_ index: YapDB.Index) -> YapItem? where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(index: YapDB.Index) -> YapItem? { + Value.Coder.Value == Value, + Metadata: NSCoding { return read { $0.readWithMetadataAtIndex(index) } } @@ -126,14 +126,14 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Value, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Value, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(indexes: Indexes) -> [YapItem] { + Value.Coder.Value == Value, + Metadata: NSCoding { return read { $0.readWithMetadataAtIndexes(indexes) } } @@ -144,12 +144,12 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readWithMetadataByKey< - Value, Metadata where + Value, Metadata>(_ key: String) -> YapItem? where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(key: String) -> YapItem? { + Value.Coder.Value == Value, + Metadata: NSCoding { return readWithMetadataAtIndex(Value.indexWithKey(key)) } @@ -160,14 +160,14 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Value, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Value, Metadata>(_ keys: Keys) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(keys: Keys) -> [YapItem] { + Value.Coder.Value == Value, + Metadata: NSCoding { return readWithMetadataAtIndexes(Value.indexesWithKeys(keys)) } @@ -177,12 +177,12 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Value, Metadata where + Value, Metadata>() -> [YapItem] where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>() -> [YapItem] { + Value.Coder.Value == Value, + Metadata: NSCoding { return read { $0.readWithMetadataAll() } } } @@ -197,12 +197,12 @@ extension WriteTransactionType { - parameter item: the item to store. */ public func writeWithMetadata< - Value, Metadata where + Value, Metadata>(_ item: YapItem) -> YapItem where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(item: YapItem) -> YapItem { + Value.Coder.Value == Value, + Metadata: NSCoding { writeAtIndex(item.value.index, object: item.value.encoded, metadata: item.metadata) return item } @@ -213,14 +213,14 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ public func writeWithMetadata< - Items, Value, Metadata where - Items: SequenceType, - Items.Generator.Element == YapItem, + Items, Value, Metadata>(_ items: Items) -> [YapItem] where + Items: Sequence, + Items.Iterator.Element == YapItem, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(items: Items) -> [YapItem] { + Value.Coder.Value == Value, + Metadata: NSCoding { return items.map(writeWithMetadata) } } @@ -233,12 +233,12 @@ extension ConnectionType { - parameter item: the item to store. */ public func writeWithMetadata< - Value, Metadata where + Value, Metadata>(_ item: YapItem) -> YapItem where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(item: YapItem) -> YapItem { + Value.Coder.Value == Value, + Metadata: NSCoding { return write { $0.writeWithMetadata(item) } } @@ -248,14 +248,14 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ public func writeWithMetadata< - Items, Value, Metadata where - Items: SequenceType, - Items.Generator.Element == YapItem, + Items, Value, Metadata>(_ items: Items) -> [YapItem] where + Items: Sequence, + Items.Iterator.Element == YapItem, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(items: Items) -> [YapItem] { + Value.Coder.Value == Value, + Metadata: NSCoding { return write { $0.writeWithMetadata(items) } } @@ -267,12 +267,12 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWriteWithMetadata< - Value, Metadata where + Value, Metadata>(_ item: YapItem, queue: DispatchQueue = DispatchQueue.main, completion: ((YapItem) -> Void)? = .none) where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(item: YapItem, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { + Value.Coder.Value == Value, + Metadata: NSCoding { asyncWrite({ $0.writeWithMetadata(item) }, queue: queue, completion: completion) } @@ -284,14 +284,14 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWriteWithMetadata< - Items, Value, Metadata where - Items: SequenceType, - Items.Generator.Element == YapItem, + Items, Value, Metadata>(_ items: Items, queue: DispatchQueue = DispatchQueue.main, completion: (([YapItem]) -> Void)? = .none) where + Items: Sequence, + Items.Iterator.Element == YapItem, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, - Metadata: NSCoding>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { + Value.Coder.Value == Value, + Metadata: NSCoding { asyncWrite({ $0.writeWithMetadata(items) }, queue: queue, completion: completion) } } diff --git a/Sources/Functional_ValueWIthValueMetadata.swift b/Sources/Functional_ValueWIthValueMetadata.swift index 19fb418..0aef12c 100644 --- a/Sources/Functional_ValueWIthValueMetadata.swift +++ b/Sources/Functional_ValueWIthValueMetadata.swift @@ -21,14 +21,14 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readWithMetadataAtIndex< - Value, Metadata where + Value, Metadata>(_ index: YapDB.Index) -> YapItem? where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> YapItem? { + Metadata.Coder.Value == Metadata { guard let item: Value = Value.decode(readAtIndex(index)) else { return nil } let metadata: Metadata? = readMetadataAtIndex(index) return YapItem(item, metadata) @@ -41,16 +41,16 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Value, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Value, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [YapItem] { + Metadata.Coder.Value == Metadata { // FIXME: using flatMap means the output length need not match the input length return indexes.flatMap(readWithMetadataAtIndex) } @@ -62,14 +62,14 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readWithMetadataByKey< - Value, Metadata where + Value, Metadata>(_ key: String) -> YapItem? where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> YapItem? { + Metadata.Coder.Value == Metadata { return readWithMetadataAtIndex(Value.indexWithKey(key)) } @@ -80,16 +80,16 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Value, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Value, Metadata>(_ keys: Keys) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [YapItem] { + Metadata.Coder.Value == Metadata { return readWithMetadataAtIndexes(Value.indexesWithKeys(keys)) } @@ -99,14 +99,14 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Value, Metadata where + Value, Metadata>() -> [YapItem] where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>() -> [YapItem] { + Metadata.Coder.Value == Metadata { return readWithMetadataByKeys(keysInCollection(Value.collection)) } } @@ -120,14 +120,14 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readWithMetadataAtIndex< - Value, Metadata where + Value, Metadata>(_ index: YapDB.Index) -> YapItem? where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> YapItem? { + Metadata.Coder.Value == Metadata { return read { $0.readWithMetadataAtIndex(index) } } @@ -138,16 +138,16 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Value, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Value, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [YapItem] { + Metadata.Coder.Value == Metadata { return read { $0.readWithMetadataAtIndexes(indexes) } } @@ -158,14 +158,14 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readWithMetadataByKey< - Value, Metadata where + Value, Metadata>(_ key: String) -> YapItem? where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> YapItem? { + Metadata.Coder.Value == Metadata { return readWithMetadataAtIndex(Value.indexWithKey(key)) } @@ -176,16 +176,16 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Value, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Value, Metadata>(_ keys: Keys) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [YapItem] { + Metadata.Coder.Value == Metadata { return readWithMetadataAtIndexes(Value.indexesWithKeys(keys)) } @@ -195,14 +195,14 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Value, Metadata where + Value, Metadata>() -> [YapItem] where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>() -> [YapItem] { + Metadata.Coder.Value == Metadata { return read { $0.readWithMetadataAll() } } } @@ -217,14 +217,14 @@ extension WriteTransactionType { - parameter item: the item to store. */ public func writeWithMetadata< - Value, Metadata where + Value, Metadata>(_ item: YapItem) -> YapItem where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(item: YapItem) -> YapItem { + Metadata.Coder.Value == Metadata { writeAtIndex(item.value.index, object: item.value.encoded, metadata: item.metadata?.encoded) return item } @@ -235,16 +235,16 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ public func writeWithMetadata< - Items, Value, Metadata where - Items: SequenceType, - Items.Generator.Element == YapItem, + Items, Value, Metadata>(_ items: Items) -> [YapItem] where + Items: Sequence, + Items.Iterator.Element == YapItem, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(items: Items) -> [YapItem] { + Metadata.Coder.Value == Metadata { return items.map(writeWithMetadata) } } @@ -257,14 +257,14 @@ extension ConnectionType { - parameter item: the item to store. */ public func writeWithMetadata< - Value, Metadata where + Value, Metadata>(_ item: YapItem) -> YapItem where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(item: YapItem) -> YapItem { + Metadata.Coder.Value == Metadata { return write { $0.writeWithMetadata(item) } } @@ -274,16 +274,16 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ public func writeWithMetadata< - Items, Value, Metadata where - Items: SequenceType, - Items.Generator.Element == YapItem, + Items, Value, Metadata>(_ items: Items) -> [YapItem] where + Items: Sequence, + Items.Iterator.Element == YapItem, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(items: Items) -> [YapItem] { + Metadata.Coder.Value == Metadata { return write { $0.writeWithMetadata(items) } } @@ -295,14 +295,14 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWriteWithMetadata< - Value, Metadata where + Value, Metadata>(_ item: YapItem, queue: DispatchQueue = DispatchQueue.main, completion: ((YapItem) -> Void)? = .none) where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(item: YapItem, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { + Metadata.Coder.Value == Metadata { asyncWrite({ $0.writeWithMetadata(item) }, queue: queue, completion: completion) } @@ -314,16 +314,16 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWriteWithMetadata< - Items, Value, Metadata where - Items: SequenceType, - Items.Generator.Element == YapItem, + Items, Value, Metadata>(_ items: Items, queue: DispatchQueue = DispatchQueue.main, completion: (([YapItem]) -> Void)? = .none) where + Items: Sequence, + Items.Iterator.Element == YapItem, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value, + Value.Coder.Value == Value, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { + Metadata.Coder.Value == Metadata { asyncWrite({ $0.writeWithMetadata(items) }, queue: queue, completion: completion) } } diff --git a/Sources/Functional_ValueWithNoMetadata.swift b/Sources/Functional_ValueWithNoMetadata.swift index a29a136..fc813d2 100644 --- a/Sources/Functional_ValueWithNoMetadata.swift +++ b/Sources/Functional_ValueWithNoMetadata.swift @@ -21,12 +21,12 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readAtIndex< - Value where + Value>(_ index: YapDB.Index) -> Value? where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(index: YapDB.Index) -> Value? { - return Value.decode(readAtIndex(index)) + Value.Coder.Value == Value { + return Value.decode(readAtIndex(index) as Any?) } /** @@ -36,13 +36,13 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, Value where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Value>(_ indexes: Indexes) -> [Value] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(indexes: Indexes) -> [Value] { + Value.Coder.Value == Value { return indexes.flatMap(readAtIndex) } @@ -53,11 +53,11 @@ extension ReadTransactionType { - returns: an optional `ItemType` */ public func readByKey< - Value where + Value>(_ key: String) -> Value? where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(key: String) -> Value? { + Value.Coder.Value == Value { return readAtIndex(Value.indexWithKey(key)) } @@ -68,13 +68,13 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, Value where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Value>(_ keys: Keys) -> [Value] where + Keys: Sequence, + Keys.Iterator.Element == String, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(keys: Keys) -> [Value] { + Value.Coder.Value == Value { return readAtIndexes(Value.indexesWithKeys(keys)) } @@ -84,11 +84,11 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAll< - Value where + Value>() -> [Value] where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>() -> [Value] { + Value.Coder.Value == Value { return readByKeys(keysInCollection(Value.collection)) } } @@ -102,11 +102,11 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readAtIndex< - Value where + Value>(_ index: YapDB.Index) -> Value? where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(index: YapDB.Index) -> Value? { + Value.Coder.Value == Value { return read { $0.readAtIndex(index) } } @@ -117,13 +117,13 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, Value where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Value>(_ indexes: Indexes) -> [Value] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(indexes: Indexes) -> [Value] { + Value.Coder.Value == Value { return read { $0.readAtIndexes(indexes) } } @@ -134,11 +134,11 @@ extension ConnectionType { - returns: an optional `ItemType` */ public func readByKey< - Value where + Value>(_ key: String) -> Value? where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(key: String) -> Value? { + Value.Coder.Value == Value { return readAtIndex(Value.indexWithKey(key)) } @@ -149,13 +149,13 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, Value where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Value>(_ keys: Keys) -> [Value] where + Keys: Sequence, + Keys.Iterator.Element == String, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(keys: Keys) -> [Value] { + Value.Coder.Value == Value { return readAtIndexes(Value.indexesWithKeys(keys)) } @@ -165,11 +165,11 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAll< - Value where + Value>() -> [Value] where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>() -> [Value] { + Value.Coder.Value == Value { return read { $0.readAll() } } } @@ -184,11 +184,11 @@ extension WriteTransactionType { - parameter item: the item to store. */ public func write< - Value where + Value>(_ item: Value) -> Value where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(item: Value) -> Value { + Value.Coder.Value == Value { writeAtIndex(item.index, object: item.encoded, metadata: .None) return item } @@ -199,13 +199,13 @@ extension WriteTransactionType { - parameter items: a SequenceType of items to store. */ public func write< - Items, Value where - Items: SequenceType, - Items.Generator.Element == Value, + Items, Value>(_ items: Items) -> [Value] where + Items: Sequence, + Items.Iterator.Element == Value, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(items: Items) -> [Value] { + Value.Coder.Value == Value { return items.map(write) } } @@ -218,11 +218,11 @@ extension ConnectionType { - parameter item: the item to store. */ public func write< - Value where + Value>(_ item: Value) -> Value where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(item: Value) -> Value { + Value.Coder.Value == Value { return write { $0.write(item) } } @@ -232,13 +232,13 @@ extension ConnectionType { - parameter items: a SequenceType of items to store. */ public func write< - Items, Value where - Items: SequenceType, - Items.Generator.Element == Value, + Items, Value>(_ items: Items) -> [Value] where + Items: Sequence, + Items.Iterator.Element == Value, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(items: Items) -> [Value] { + Value.Coder.Value == Value { return write { $0.write(items) } } @@ -250,11 +250,11 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - Value where + Value>(_ item: Value, queue: DispatchQueue = DispatchQueue.main, completion: ((Value) -> Void)? = .none) where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(item: Value, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (Value -> Void)? = .None) { + Value.Coder.Value == Value { asyncWrite({ $0.write(item) }, queue: queue, completion: completion) } @@ -266,13 +266,13 @@ extension ConnectionType { - parameter completion: a dispatch_block_t for completion. */ public func asyncWrite< - Items, Value where - Items: SequenceType, - Items.Generator.Element == Value, + Items, Value>(_ items: Items, queue: DispatchQueue = DispatchQueue.main, completion: (([Value]) -> Void)? = .none) where + Items: Sequence, + Items.Iterator.Element == Value, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, - Value.Coder.ValueType == Value>(items: Items, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([Value] -> Void)? = .None) { + Value.Coder.Value == Value { asyncWrite({ $0.write(items) }, queue: queue, completion: completion) } } diff --git a/Sources/Persistable_AnyWithObjectMetadata.swift b/Sources/Persistable_AnyWithObjectMetadata.swift index fbe08ed..a216d76 100644 --- a/Sources/Persistable_AnyWithObjectMetadata.swift +++ b/Sources/Persistable_AnyWithObjectMetadata.swift @@ -14,23 +14,23 @@ import ValueCoding extension Readable where ItemType: Persistable { - func metadataInTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> Metadata? { + func metadataInTransaction(_ transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> Metadata? { return transaction.readMetadataAtIndex(index) } - func metadataAtIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> Metadata? { + func metadataAtIndexInTransaction(_ index: YapDB.Index) -> (Database.Connection.ReadTransaction) -> Metadata? { return { self.metadataInTransaction($0, atIndex: index) } } - func metadataInTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> Metadata? { + func metadataInTransactionAtIndex(_ transaction: Database.Connection.ReadTransaction) -> (YapDB.Index) -> Metadata? { return { self.metadataInTransaction(transaction, atIndex: $0) } } func metadataAtIndexesInTransaction< - Indexes, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, - Metadata: NSCoding>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [Metadata] { + Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [Metadata] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, + Metadata: NSCoding { return { indexes.flatMap(self.metadataInTransactionAtIndex($0)) } } @@ -41,8 +41,8 @@ extension Readable where - returns: an optional `Metadata` */ public func metadataAtIndex< - Metadata where - Metadata: NSCoding>(index: YapDB.Index) -> Metadata? { + Metadata>(_ index: YapDB.Index) -> Metadata? where + Metadata: NSCoding { return sync(metadataAtIndexInTransaction(index)) } @@ -53,10 +53,10 @@ extension Readable where - returns: an array of `Metadata` */ public func metadataAtIndexes< - Indexes, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, - Metadata: NSCoding>(indexes: Indexes) -> [Metadata] { + Indexes, Metadata>(_ indexes: Indexes) -> [Metadata] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, + Metadata: NSCoding { return sync(metadataAtIndexesInTransaction(indexes)) } } diff --git a/Sources/Persistable_AnyWithValueMetadata.swift b/Sources/Persistable_AnyWithValueMetadata.swift index 9147903..0fd6211 100644 --- a/Sources/Persistable_AnyWithValueMetadata.swift +++ b/Sources/Persistable_AnyWithValueMetadata.swift @@ -15,36 +15,36 @@ extension Readable where ItemType: Persistable { func metadataInTransaction< - Metadata where + Metadata>(_ transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> Metadata? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> Metadata? { + Metadata.Coder.Value == Metadata { return transaction.readMetadataAtIndex(index) } func metadataAtIndexInTransaction< - Metadata where + Metadata>(_ index: YapDB.Index) -> (Database.Connection.ReadTransaction) -> Metadata? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Database.Connection.ReadTransaction -> Metadata? { + Metadata.Coder.Value == Metadata { return { self.metadataInTransaction($0, atIndex: index) } } func metadataInTransactionAtIndex< - Metadata where + Metadata>(_ transaction: Database.Connection.ReadTransaction) -> (YapDB.Index) -> Metadata? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> Metadata? { + Metadata.Coder.Value == Metadata { return { self.metadataInTransaction(transaction, atIndex: $0) } } func metadataAtIndexesInTransaction< - Indexes, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [Metadata] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [Metadata] { + Metadata.Coder.Value == Metadata { return { indexes.flatMap(self.metadataInTransactionAtIndex($0)) } } @@ -55,10 +55,10 @@ extension Readable where - returns: an optional `Metadata` */ public func metadataAtIndex< - Metadata where + Metadata>(_ index: YapDB.Index) -> Metadata? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Metadata? { + Metadata.Coder.Value == Metadata { return sync(metadataAtIndexInTransaction(index)) } @@ -69,12 +69,12 @@ extension Readable where - returns: an array of `Metadata` */ public func metadataAtIndexes< - Indexes, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Metadata>(_ indexes: Indexes) -> [Metadata] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [Metadata] { + Metadata.Coder.Value == Metadata { return sync(metadataAtIndexesInTransaction(indexes)) } } diff --git a/Sources/Persistable_ObjectWithObjectMetadata.swift b/Sources/Persistable_ObjectWithObjectMetadata.swift index abc3f22..b128acf 100644 --- a/Sources/Persistable_ObjectWithObjectMetadata.swift +++ b/Sources/Persistable_ObjectWithObjectMetadata.swift @@ -22,9 +22,9 @@ extension Persistable where - returns: the receiver. */ public func writeWithMetadata< - WriteTransaction, Metadata where + WriteTransaction, Metadata>(_ transaction: WriteTransaction, metadata: Metadata?) -> YapItem where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata?) -> YapItem { + Metadata: NSCoding { return transaction.writeWithMetadata(YapItem(self, metadata)) } @@ -35,9 +35,9 @@ extension Persistable where - returns: the receiver. */ public func writeWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?) -> YapItem where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> YapItem { + Metadata: NSCoding { return connection.writeWithMetadata(YapItem(self, metadata)) } @@ -48,9 +48,9 @@ extension Persistable where - returns: a closure which receives as an argument the receiver of this function. */ public func asyncWriteWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?, queue: DispatchQueue = DispatchQueue.main, completion: ((YapItem) -> Void)? = .none) where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { + Metadata: NSCoding { return connection.asyncWriteWithMetadata(YapItem(self, metadata), queue: queue, completion: completion) } @@ -61,16 +61,16 @@ extension Persistable where - returns: an `NSOperation` */ public func writeWithMetadataOperation< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?) -> Operation where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> NSOperation { - return NSBlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } + Metadata: NSCoding { + return BlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } } } -extension SequenceType where - Generator.Element: Persistable, - Generator.Element: NSCoding { +extension Sequence where + Iterator.Element: Persistable, + Iterator.Element: NSCoding { /** Zips the receiver with metadata into an array of YapItem. @@ -80,10 +80,10 @@ extension SequenceType where - returns: an array where Persistables and Metadata with corresponding indexes in `self` and `metadata` are joined in a `YapItem` */ public func yapItems< - Metadatas, Metadata where + Metadatas, Metadata>(with metadata: Metadatas) -> [YapItem] where Metadata: NSCoding, - Metadatas: SequenceType, - Metadatas.Generator.Element == Optional>(with metadata: Metadatas) -> [YapItem] { + Metadatas: Sequence, + Metadatas.Iterator.Element == Optional { return zip(self, metadata).map { YapItem($0, $1) } } @@ -94,9 +94,9 @@ extension SequenceType where - returns: the receiver. */ public func writeWithMetadata< - WriteTransaction, Metadata where + WriteTransaction, Metadata>(_ transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] { + Metadata: NSCoding { let items = yapItems(with: metadata) return transaction.writeWithMetadata(items) } @@ -108,9 +108,9 @@ extension SequenceType where - returns: the receiver. */ public func writeWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?]) -> [YapItem] where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> [YapItem] { + Metadata: NSCoding { let items = yapItems(with: metadata) return connection.writeWithMetadata(items) } @@ -122,9 +122,9 @@ extension SequenceType where - returns: a closure which receives as an argument the receiver of this function. */ public func asyncWriteWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?], queue: DispatchQueue = DispatchQueue.main, completion: (([YapItem]) -> Void)? = .none) where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { + Metadata: NSCoding { let items = yapItems(with: metadata) return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } @@ -136,11 +136,11 @@ extension SequenceType where - returns: an `NSOperation` */ public func writeWithMetadataOperation< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?]) -> Operation where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> NSOperation { + Metadata: NSCoding { let items = yapItems(with: metadata) - return NSBlockOperation { connection.writeWithMetadata(items) } + return BlockOperation { connection.writeWithMetadata(items) } } } @@ -151,39 +151,39 @@ extension Readable where ItemType: NSCoding, ItemType: Persistable { - func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> YapItem? { + func withMetadataInTransaction(_ transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> YapItem? { return transaction.readWithMetadataAtIndex(index) } - func withMetadataInTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> YapItem? { + func withMetadataInTransactionAtIndex(_ transaction: Database.Connection.ReadTransaction) -> (YapDB.Index) -> YapItem? { return { self.withMetadataInTransaction(transaction, atIndex: $0) } } - func withMetadataAtIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> YapItem? { + func withMetadataAtIndexInTransaction(_ index: YapDB.Index) -> (Database.Connection.ReadTransaction) -> YapItem? { return { self.withMetadataInTransaction($0, atIndex: index) } } func withMetadataAtIndexesInTransaction< - Indexes, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, - Metadata: NSCoding>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [YapItem] { + Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, + Metadata: NSCoding { return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } } - func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? { + func withMetadataInTransaction(_ transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? { return withMetadataInTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func withMetadataInTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> YapItem? { + func withMetadataInTransactionByKey(_ transaction: Database.Connection.ReadTransaction) -> (String) -> YapItem? { return { self.withMetadataInTransaction(transaction, byKey: $0) } } - func withMetadataByKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> YapItem? { + func withMetadataByKeyInTransaction(_ key: String) -> (Database.Connection.ReadTransaction) -> YapItem? { return { self.withMetadataInTransaction($0, byKey: key) } } - func withMetadataByKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [YapItem] { + func withMetadataByKeysInTransaction(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [YapItem] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) @@ -196,7 +196,7 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func withMetadataAtIndex(index: YapDB.Index) -> YapItem? { + public func withMetadataAtIndex(_ index: YapDB.Index) -> YapItem? { return sync(withMetadataAtIndexInTransaction(index)) } @@ -207,10 +207,10 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataAtIndexes< - Indexes, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, - Metadata: NSCoding>(indexes: Indexes) -> [YapItem] { + Indexes, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, + Metadata: NSCoding { return sync(withMetadataAtIndexesInTransaction(indexes)) } @@ -220,7 +220,7 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func withMetadataByKey(key: String) -> YapItem? { + public func withMetadataByKey(_ key: String) -> YapItem? { return sync(withMetadataByKeyInTransaction(key)) } @@ -231,10 +231,10 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataByKeys< - Keys, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, - Metadata: NSCoding>(keys: Keys) -> [YapItem] { + Keys, Metadata>(_ keys: Keys) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, + Metadata: NSCoding { return sync(withMetadataByKeysInTransaction(Array(keys))) } @@ -253,8 +253,8 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func withMetadataFilterExisting(keys: [String]) -> (existing: [YapItem], missing: [String]) { - let existingInTransaction: Database.Connection.ReadTransaction -> [YapItem] = withMetadataByKeysInTransaction(keys) + public func withMetadataFilterExisting(_ keys: [String]) -> (existing: [YapItem], missing: [String]) { + let existingInTransaction: (Database.Connection.ReadTransaction) -> [YapItem] = withMetadataByKeysInTransaction(keys) return sync { transaction -> ([YapItem], [String]) in let existing = existingInTransaction(transaction) let existingKeys = existing.map {keyForPersistable($0.value)} diff --git a/Sources/Persistable_ObjectWithValueMetadata.swift b/Sources/Persistable_ObjectWithValueMetadata.swift index 3ca949f..d19d97c 100644 --- a/Sources/Persistable_ObjectWithValueMetadata.swift +++ b/Sources/Persistable_ObjectWithValueMetadata.swift @@ -23,11 +23,11 @@ extension Persistable where - returns: the receiver. */ public func writeWithMetadata< - WriteTransaction, Metadata where + WriteTransaction, Metadata>(_ transaction: WriteTransaction, metadata: Metadata?) -> YapItem where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata?) -> YapItem { + Metadata.Coder.Value == Metadata { return transaction.writeWithMetadata(YapItem(self, metadata)) } @@ -38,11 +38,11 @@ extension Persistable where - returns: the receiver. */ public func writeWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?) -> YapItem where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> YapItem { + Metadata.Coder.Value == Metadata { return connection.writeWithMetadata(YapItem(self, metadata)) } @@ -53,11 +53,11 @@ extension Persistable where - returns: a closure which receives as an argument the receiver of this function. */ public func asyncWriteWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?, queue: DispatchQueue = DispatchQueue.main, completion: ((YapItem) -> Void)? = .none) where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { + Metadata.Coder.Value == Metadata { return connection.asyncWriteWithMetadata(YapItem(self, metadata), queue: queue, completion: completion) } @@ -68,18 +68,18 @@ extension Persistable where - returns: an `NSOperation` */ public func writeWithMetadataOperation< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?) -> Operation where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> NSOperation { - return NSBlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } + Metadata.Coder.Value == Metadata { + return BlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } } } -extension SequenceType where - Generator.Element: Persistable, - Generator.Element: NSCoding { +extension Sequence where + Iterator.Element: Persistable, + Iterator.Element: NSCoding { /** Zips the receiver with metadata into an array of YapItem. @@ -89,12 +89,12 @@ extension SequenceType where - returns: an array where Persistables and Metadata with corresponding indexes in `self` and `metadata` are joined in a `YapItem` */ public func yapItems< - Metadatas, Metadata where + Metadatas, Metadata>(with metadata: Metadatas) -> [YapItem] where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata, - Metadatas: SequenceType, - Metadatas.Generator.Element == Optional>(with metadata: Metadatas) -> [YapItem] { + Metadata.Coder.Value == Metadata, + Metadatas: Sequence, + Metadatas.Iterator.Element == Optional { return zip(self, metadata).map { YapItem($0, $1) } } @@ -105,11 +105,11 @@ extension SequenceType where - returns: the receiver. */ public func writeWithMetadata< - WriteTransaction, Metadata where + WriteTransaction, Metadata>(_ transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] { + Metadata.Coder.Value == Metadata { let items = yapItems(with: metadata) return transaction.writeWithMetadata(items) } @@ -121,11 +121,11 @@ extension SequenceType where - returns: the receiver. */ public func writeWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?]) -> [YapItem] where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> [YapItem] { + Metadata.Coder.Value == Metadata { let items = yapItems(with: metadata) return connection.writeWithMetadata(items) } @@ -137,11 +137,11 @@ extension SequenceType where - returns: a closure which receives as an argument the receiver of this function. */ public func asyncWriteWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?], queue: DispatchQueue = DispatchQueue.main, completion: (([YapItem]) -> Void)? = .none) where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { + Metadata.Coder.Value == Metadata { let items = yapItems(with: metadata) return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } @@ -153,13 +153,13 @@ extension SequenceType where - returns: an `NSOperation` */ public func writeWithMetadataOperation< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?]) -> Operation where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> NSOperation { + Metadata.Coder.Value == Metadata { let items = yapItems(with: metadata) - return NSBlockOperation { connection.writeWithMetadata(items) } + return BlockOperation { connection.writeWithMetadata(items) } } } @@ -170,68 +170,68 @@ extension Readable where ItemType: Persistable { func withMetadataInTransaction< - Metadata where + Metadata>(_ transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> YapItem? { + Metadata.Coder.Value == Metadata { return transaction.readWithMetadataAtIndex(index) } func withMetadataInTransactionAtIndex< - Metadata where + Metadata>(_ transaction: Database.Connection.ReadTransaction) -> (YapDB.Index) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> YapItem? { + Metadata.Coder.Value == Metadata { return { self.withMetadataInTransaction(transaction, atIndex: $0) } } func withMetadataAtIndexInTransaction< - Metadata where + Metadata>(_ index: YapDB.Index) -> (Database.Connection.ReadTransaction) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Database.Connection.ReadTransaction -> YapItem? { + Metadata.Coder.Value == Metadata { return { self.withMetadataInTransaction($0, atIndex: index) } } func withMetadataAtIndexesInTransaction< - Indexes, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [YapItem] { + Metadata.Coder.Value == Metadata { return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } } func withMetadataInTransaction< - Metadata where + Metadata>(_ transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? { + Metadata.Coder.Value == Metadata { return withMetadataInTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } func withMetadataInTransactionByKey< - Metadata where + Metadata>(_ transaction: Database.Connection.ReadTransaction) -> (String) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> String -> YapItem? { + Metadata.Coder.Value == Metadata { return { self.withMetadataInTransaction(transaction, byKey: $0) } } func withMetadataByKeyInTransaction< - Metadata where + Metadata>(_ key: String) -> (Database.Connection.ReadTransaction) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> Database.Connection.ReadTransaction -> YapItem? { + Metadata.Coder.Value == Metadata { return { self.withMetadataInTransaction($0, byKey: key) } } func withMetadataByKeysInTransaction< - Metadata where + Metadata>(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [YapItem] where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [YapItem] { + Metadata.Coder.Value == Metadata { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) @@ -245,10 +245,10 @@ extension Readable where - returns: an optional `ItemType` */ public func withMetadataAtIndex< - Metadata where + Metadata>(_ index: YapDB.Index) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> YapItem? { + Metadata.Coder.Value == Metadata { return sync(withMetadataAtIndexInTransaction(index)) } @@ -259,12 +259,12 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataAtIndexes< - Indexes, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [YapItem] { + Metadata.Coder.Value == Metadata { return sync(withMetadataAtIndexesInTransaction(indexes)) } @@ -275,10 +275,10 @@ extension Readable where - returns: an optional `ItemType` */ public func withMetadataByKey< - Metadata where + Metadata>(_ key: String) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> YapItem? { + Metadata.Coder.Value == Metadata { return sync(withMetadataByKeyInTransaction(key)) } @@ -289,12 +289,12 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataByKeys< - Keys, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Metadata>(_ keys: Keys) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [YapItem] { + Metadata.Coder.Value == Metadata { return sync(withMetadataByKeysInTransaction(Array(keys))) } @@ -304,10 +304,10 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataAll< - Metadata where + Metadata>() -> [YapItem] where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>() -> [YapItem] { + Metadata.Coder.Value == Metadata { return sync(withMetadataByKeysInTransaction()) } @@ -318,11 +318,11 @@ extension Readable where - returns: a tuple of type `([ItemType], [String])` */ public func withMetadataFilterExisting< - Metadata where + Metadata>(_ keys: [String]) -> (existing: [YapItem], missing: [String]) where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: [String]) -> (existing: [YapItem], missing: [String]) { - let existingInTransaction: Database.Connection.ReadTransaction -> [YapItem] = withMetadataByKeysInTransaction(keys) + Metadata.Coder.Value == Metadata { + let existingInTransaction: (Database.Connection.ReadTransaction) -> [YapItem] = withMetadataByKeysInTransaction(keys) return sync { transaction -> ([YapItem], [String]) in let existing = existingInTransaction(transaction) let existingKeys = existing.map {keyForPersistable($0.value)} diff --git a/Sources/Persistable_Remove.swift b/Sources/Persistable_Remove.swift index c99913f..c003161 100644 --- a/Sources/Persistable_Remove.swift +++ b/Sources/Persistable_Remove.swift @@ -12,7 +12,7 @@ extension Persistable { - parameter transaction: a `WriteTransactionType` transaction */ - public func remove(transaction: WriteTransaction) { + public func remove(_ transaction: WriteTransaction) { transaction.remove(self) } @@ -21,7 +21,7 @@ extension Persistable { - parameter connection: a `ConnectionType` connection */ - public func remove(connection: Connection) { + public func remove(_ connection: Connection) { connection.remove(self) } @@ -30,7 +30,7 @@ extension Persistable { - parameter connection: a `ConnectionType` connection */ - public func asyncRemove(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: dispatch_block_t? = .None) { + public func asyncRemove(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: ()->()? = .none) { connection.asyncRemove(self, queue: queue, completion: completion) } @@ -40,20 +40,20 @@ extension Persistable { - parameter connection: a `ConnectionType` connection */ - public func removeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.remove(self) } + public func removeOperation(_ connection: Connection) -> Operation { + return BlockOperation { connection.remove(self) } } } -extension SequenceType where -Generator.Element: Persistable { +extension Sequence where +Iterator.Element: Persistable { /** Removes the receiver using the write transaction. - parameter transaction: a `WriteTransactionType` transaction */ - public func remove(transaction: WriteTransaction) { + public func remove(_ transaction: WriteTransaction) { transaction.remove(self) } @@ -62,7 +62,7 @@ Generator.Element: Persistable { - parameter connection: a `ConnectionType` connection */ - public func remove(connection: Connection) { + public func remove(_ connection: Connection) { connection.remove(self) } @@ -71,7 +71,7 @@ Generator.Element: Persistable { - parameter connection: a `ConnectionType` connection */ - public func asyncRemove(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: dispatch_block_t? = .None) { + public func asyncRemove(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: ()->()? = .none) { connection.asyncRemove(self, queue: queue, completion: completion) } @@ -81,8 +81,8 @@ Generator.Element: Persistable { - parameter connection: a `ConnectionType` connection */ - public func removeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.remove(self) } + public func removeOperation(_ connection: Connection) -> Operation { + return BlockOperation { connection.remove(self) } } } diff --git a/Sources/Persistable_ValueWithNoMetadata.swift b/Sources/Persistable_ValueWithNoMetadata.swift index 3e19487..dec1657 100644 --- a/Sources/Persistable_ValueWithNoMetadata.swift +++ b/Sources/Persistable_ValueWithNoMetadata.swift @@ -14,7 +14,7 @@ import ValueCoding extension Persistable where Self: ValueCoding, Self.Coder: NSCoding, - Self.Coder.ValueType == Self { + Self.Coder.Value == Self { // Writing @@ -24,7 +24,7 @@ extension Persistable where - parameter transaction: a YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(transaction: WriteTransaction) -> Self { + public func write(_ transaction: WriteTransaction) -> Self { return transaction.write(self) } @@ -34,7 +34,7 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: the receiver. */ - public func write(connection: Connection) -> Self { + public func write(_ connection: Connection) -> Self { return connection.write(self) } @@ -44,7 +44,7 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (Self -> Void)? = .None) { + public func asyncWrite(_ connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self) -> Void)? = .none) { return connection.asyncWrite(self, queue: queue, completion: completion) } @@ -54,16 +54,16 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.write(self) } + public func writeOperation(_ connection: Connection) -> Operation { + return BlockOperation { connection.write(self) } } } -extension SequenceType where - Generator.Element: Persistable, - Generator.Element: ValueCoding, - Generator.Element.Coder: NSCoding, - Generator.Element.Coder.ValueType == Generator.Element { +extension Sequence where + Iterator.Element: Persistable, + Iterator.Element: ValueCoding, + Iterator.Element.Coder: NSCoding, + Iterator.Element.Coder.Value == Iterator.Element { /** Write the items using an existing transaction. @@ -71,7 +71,7 @@ extension SequenceType where - parameter transaction: a WriteTransactionType e.g. YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(transaction: WriteTransaction) -> [Generator.Element] { + public func write(_ transaction: WriteTransaction) -> [Generator.Element] { return transaction.write(self) } @@ -81,7 +81,7 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: the receiver. */ - public func write(connection: Connection) -> [Generator.Element] { + public func write(_ connection: Connection) -> [Generator.Element] { return connection.write(self) } @@ -91,7 +91,7 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([Generator.Element] -> Void)? = .None) { + public func asyncWrite(_ connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (([Generator.Element]) -> Void)? = .None) { return connection.asyncWrite(self, queue: queue, completion: completion) } @@ -101,8 +101,8 @@ extension SequenceType where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.write(self) } + public func writeOperation(_ connection: Connection) -> Operation { + return BlockOperation { connection.write(self) } } } @@ -112,41 +112,41 @@ extension Readable where ItemType: ValueCoding, ItemType: Persistable, ItemType.Coder: NSCoding, - ItemType.Coder.ValueType == ItemType { + ItemType.Coder.Value == ItemType { - func inTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> ItemType? { + func inTransaction(_ transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> ItemType? { return transaction.readAtIndex(index) } - func inTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> ItemType? { + func inTransactionAtIndex(_ transaction: Database.Connection.ReadTransaction) -> (YapDB.Index) -> ItemType? { return { self.inTransaction(transaction, atIndex: $0) } } - func atIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> ItemType? { + func atIndexInTransaction(_ index: YapDB.Index) -> (Database.Connection.ReadTransaction) -> ItemType? { return { self.inTransaction($0, atIndex: index) } } func atIndexesInTransaction< - Indexes where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [ItemType] { + Indexes>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [ItemType] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index { let atIndex = inTransactionAtIndex return { indexes.flatMap(atIndex($0)) } } - func inTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> ItemType? { + func inTransaction(_ transaction: Database.Connection.ReadTransaction, byKey key: String) -> ItemType? { return inTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func inTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> ItemType? { + func inTransactionByKey(_ transaction: Database.Connection.ReadTransaction) -> (String) -> ItemType? { return { self.inTransaction(transaction, byKey: $0) } } - func byKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> ItemType? { + func byKeyInTransaction(_ key: String) -> (Database.Connection.ReadTransaction) -> ItemType? { return { self.inTransaction($0, byKey: key) } } - func byKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [ItemType] { + func byKeysInTransaction(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [ItemType] { let byKey = inTransactionByKey return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) @@ -160,7 +160,7 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func atIndex(index: YapDB.Index) -> ItemType? { + public func atIndex(_ index: YapDB.Index) -> ItemType? { return sync(atIndexInTransaction(index)) } @@ -171,9 +171,9 @@ extension Readable where - returns: an array of `ItemType` */ public func atIndexes< - Indexes where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> [ItemType] { + Indexes>(_ indexes: Indexes) -> [ItemType] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index { return sync(atIndexesInTransaction(indexes)) } @@ -183,7 +183,7 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func byKey(key: String) -> ItemType? { + public func byKey(_ key: String) -> ItemType? { return sync(byKeyInTransaction(key)) } @@ -194,9 +194,9 @@ extension Readable where - returns: an array of `ItemType` */ public func byKeys< - Keys where - Keys: SequenceType, - Keys.Generator.Element == String>(keys: Keys) -> [ItemType] { + Keys>(_ keys: Keys) -> [ItemType] where + Keys: Sequence, + Keys.Iterator.Element == String { return sync(byKeysInTransaction(Array(keys))) } @@ -215,7 +215,7 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func filterExisting(keys: [String]) -> (existing: [ItemType], missing: [String]) { + public func filterExisting(_ keys: [String]) -> (existing: [ItemType], missing: [String]) { let existingInTransaction = byKeysInTransaction(keys) return sync { transaction -> ([ItemType], [String]) in let existing = existingInTransaction(transaction) diff --git a/Sources/Persistable_ValueWithObjectMetadata.swift b/Sources/Persistable_ValueWithObjectMetadata.swift index bbabc82..1bd9804 100644 --- a/Sources/Persistable_ValueWithObjectMetadata.swift +++ b/Sources/Persistable_ValueWithObjectMetadata.swift @@ -14,7 +14,7 @@ import ValueCoding extension Persistable where Self: ValueCoding, Self.Coder: NSCoding, - Self.Coder.ValueType == Self { + Self.Coder.Value == Self { // Writing @@ -25,9 +25,9 @@ extension Persistable where - returns: the receiver. */ public func writeWithMetadata< - WriteTransaction, Metadata where + WriteTransaction, Metadata>(_ transaction: WriteTransaction, metadata: Metadata?) -> YapItem where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: Metadata?) -> YapItem { + Metadata: NSCoding { return transaction.writeWithMetadata(YapItem(self, metadata)) } @@ -38,9 +38,9 @@ extension Persistable where - returns: the receiver. */ public func writeWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?) -> YapItem where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> YapItem { + Metadata: NSCoding { return connection.writeWithMetadata(YapItem(self, metadata)) } @@ -51,9 +51,9 @@ extension Persistable where - returns: a closure which receives as an argument the receiver of this function. */ public func asyncWriteWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((YapItem) -> Void)? = .none) where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { + Metadata: NSCoding { return connection.asyncWriteWithMetadata(YapItem(self, metadata), queue: queue, completion: completion) } @@ -64,18 +64,18 @@ extension Persistable where - returns: an `NSOperation` */ public func writeWithMetadataOperation< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?) -> Operation where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: Metadata?) -> NSOperation { - return NSBlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } + Metadata: NSCoding { + return BlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } } } -extension SequenceType where - Generator.Element: Persistable, - Generator.Element: ValueCoding, - Generator.Element.Coder: NSCoding, - Generator.Element.Coder.ValueType == Generator.Element { +extension Sequence where + Iterator.Element: Persistable, + Iterator.Element: ValueCoding, + Iterator.Element.Coder: NSCoding, + Iterator.Element.Coder.Value == Iterator.Element { /** Zips the receiver with metadata into an array of YapItem. @@ -85,10 +85,10 @@ extension SequenceType where - returns: an array where Persistables and Metadata with corresponding indexes in `self` and `metadata` are joined in a `YapItem` */ public func yapItems< - Metadatas, Metadata where + Metadatas, Metadata>(with metadata: Metadatas) -> [YapItem] where Metadata: NSCoding, - Metadatas: SequenceType, - Metadatas.Generator.Element == Optional>(with metadata: Metadatas) -> [YapItem] { + Metadatas: Sequence, + Metadatas.Iterator.Element == Optional { return zip(self, metadata).map { YapItem($0, $1) } } @@ -99,9 +99,9 @@ extension SequenceType where - returns: the receiver. */ public func writeWithMetadata< - WriteTransaction, Metadata where + WriteTransaction, Metadata>(_ transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] where WriteTransaction: WriteTransactionType, - Metadata: NSCoding>(transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] { + Metadata: NSCoding { let items = yapItems(with: metadata) return transaction.writeWithMetadata(items) } @@ -113,9 +113,9 @@ extension SequenceType where - returns: the receiver. */ public func writeWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?]) -> [YapItem] where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> [YapItem] { + Metadata: NSCoding { let items = yapItems(with: metadata) return connection.writeWithMetadata(items) } @@ -127,9 +127,9 @@ extension SequenceType where - returns: a closure which receives as an argument the receiver of this function. */ public func asyncWriteWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (([YapItem]) -> Void)? = .None) where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { + Metadata: NSCoding { let items = yapItems(with: metadata) return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } @@ -141,11 +141,11 @@ extension SequenceType where - returns: an `NSOperation` */ public func writeWithMetadataOperation< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?]) -> Operation where Connection: ConnectionType, - Metadata: NSCoding>(connection: Connection, metadata: [Metadata?]) -> NSOperation { + Metadata: NSCoding { let items = yapItems(with: metadata) - return NSBlockOperation { connection.writeWithMetadata(items) } + return BlockOperation { connection.writeWithMetadata(items) } } } @@ -156,41 +156,41 @@ extension Readable where ItemType: ValueCoding, ItemType: Persistable, ItemType.Coder: NSCoding, - ItemType.Coder.ValueType == ItemType { + ItemType.Coder.Value == ItemType { - func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> YapItem? { + func withMetadataInTransaction(_ transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> YapItem? { return transaction.readWithMetadataAtIndex(index) } - func withMetadataInTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> YapItem? { + func withMetadataInTransactionAtIndex(_ transaction: Database.Connection.ReadTransaction) -> (YapDB.Index) -> YapItem? { return { self.withMetadataInTransaction(transaction, atIndex: $0) } } - func withMetadataAtIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> YapItem? { + func withMetadataAtIndexInTransaction(_ index: YapDB.Index) -> (Database.Connection.ReadTransaction) -> YapItem? { return { self.withMetadataInTransaction($0, atIndex: index) } } func withMetadataAtIndexesInTransaction< - Indexes, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, - Metadata: NSCoding>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [YapItem] { + Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, + Metadata: NSCoding { return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } } - func withMetadataInTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? { + func withMetadataInTransaction(_ transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? { return withMetadataInTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func withMetadataInTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> YapItem? { + func withMetadataInTransactionByKey(_ transaction: Database.Connection.ReadTransaction) -> (String) -> YapItem? { return { self.withMetadataInTransaction(transaction, byKey: $0) } } - func withMetadataByKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> YapItem? { + func withMetadataByKeyInTransaction(_ key: String) -> (Database.Connection.ReadTransaction) -> YapItem? { return { self.withMetadataInTransaction($0, byKey: key) } } - func withMetadataByKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [YapItem] { + func withMetadataByKeysInTransaction(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [YapItem] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) @@ -203,7 +203,7 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func withMetadataAtIndex(index: YapDB.Index) -> YapItem? { + public func withMetadataAtIndex(_ index: YapDB.Index) -> YapItem? { return sync(withMetadataAtIndexInTransaction(index)) } @@ -214,10 +214,10 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataAtIndexes< - Indexes, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, - Metadata: NSCoding>(indexes: Indexes) -> [YapItem] { + Indexes, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, + Metadata: NSCoding { return sync(withMetadataAtIndexesInTransaction(indexes)) } @@ -227,7 +227,7 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func withMetadataByKey(key: String) -> YapItem? { + public func withMetadataByKey(_ key: String) -> YapItem? { return sync(withMetadataByKeyInTransaction(key)) } @@ -238,10 +238,10 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataByKeys< - Keys, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, - Metadata: NSCoding>(keys: Keys) -> [YapItem] { + Keys, Metadata>(_ keys: Keys) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, + Metadata: NSCoding { return sync(withMetadataByKeysInTransaction(Array(keys))) } @@ -260,8 +260,8 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func withMetadataFilterExisting(keys: [String]) -> (existing: [YapItem], missing: [String]) { - let existingInTransaction: Database.Connection.ReadTransaction -> [YapItem] = withMetadataByKeysInTransaction(keys) + public func withMetadataFilterExisting(_ keys: [String]) -> (existing: [YapItem], missing: [String]) { + let existingInTransaction: (Database.Connection.ReadTransaction) -> [YapItem] = withMetadataByKeysInTransaction(keys) return sync { transaction -> ([YapItem], [String]) in let existing = existingInTransaction(transaction) let existingKeys = existing.map {keyForPersistable($0.value)} diff --git a/Sources/Persistable_ValueWithValueMetadata.swift b/Sources/Persistable_ValueWithValueMetadata.swift index c7c4912..b59b119 100644 --- a/Sources/Persistable_ValueWithValueMetadata.swift +++ b/Sources/Persistable_ValueWithValueMetadata.swift @@ -14,7 +14,7 @@ import ValueCoding extension Persistable where Self: ValueCoding, Self.Coder: NSCoding, - Self.Coder.ValueType == Self { + Self.Coder.Value == Self { // Writing @@ -25,11 +25,11 @@ extension Persistable where - returns: the receiver. */ public func writeWithMetadata< - WriteTransaction, Metadata where + WriteTransaction, Metadata>(_ transaction: WriteTransaction, metadata: Metadata?) -> YapItem where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: Metadata?) -> YapItem { + Metadata.Coder.Value == Metadata { return transaction.writeWithMetadata(YapItem(self, metadata)) } @@ -40,11 +40,11 @@ extension Persistable where - returns: the receiver. */ public func writeWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?) -> YapItem where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> YapItem { + Metadata.Coder.Value == Metadata { return connection.writeWithMetadata(YapItem(self, metadata)) } @@ -55,11 +55,11 @@ extension Persistable where - returns: a closure which receives as an argument the receiver of this function. */ public func asyncWriteWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((YapItem) -> Void)? = .none) where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (YapItem -> Void)? = .None) { + Metadata.Coder.Value == Metadata { return connection.asyncWriteWithMetadata(YapItem(self, metadata), queue: queue, completion: completion) } @@ -70,20 +70,20 @@ extension Persistable where - returns: an `NSOperation` */ public func writeWithMetadataOperation< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?) -> Operation where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: Metadata?) -> NSOperation { - return NSBlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } + Metadata.Coder.Value == Metadata { + return BlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } } } -extension SequenceType where - Generator.Element: Persistable, - Generator.Element: ValueCoding, - Generator.Element.Coder: NSCoding, - Generator.Element.Coder.ValueType == Generator.Element { +extension Sequence where + Iterator.Element: Persistable, + Iterator.Element: ValueCoding, + Iterator.Element.Coder: NSCoding, + Iterator.Element.Coder.Value == Iterator.Element { /** Zips the receiver with metadata into an array of YapItem. @@ -93,12 +93,12 @@ extension SequenceType where - returns: an array where Persistables and Metadata with corresponding indexes in `self` and `metadata` are joined in a `YapItem` */ public func yapItems< - Metadatas, Metadata where + Metadatas, Metadata>(with metadata: Metadatas) -> [YapItem] where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata, - Metadatas: SequenceType, - Metadatas.Generator.Element == Optional>(with metadata: Metadatas) -> [YapItem] { + Metadata.Coder.Value == Metadata, + Metadatas: Sequence, + Metadatas.Iterator.Element == Optional { return zip(self, metadata).map { YapItem($0, $1) } } @@ -109,11 +109,11 @@ extension SequenceType where - returns: the receiver. */ public func writeWithMetadata< - WriteTransaction, Metadata where + WriteTransaction, Metadata>(_ transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] { + Metadata.Coder.Value == Metadata { let items = yapItems(with: metadata) return transaction.writeWithMetadata(items) } @@ -125,11 +125,11 @@ extension SequenceType where - returns: the receiver. */ public func writeWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?]) -> [YapItem] where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> [YapItem] { + Metadata.Coder.Value == Metadata { let items = yapItems(with: metadata) return connection.writeWithMetadata(items) } @@ -141,11 +141,11 @@ extension SequenceType where - returns: a closure which receives as an argument the receiver of this function. */ public func asyncWriteWithMetadata< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (([YapItem]) -> Void)? = .None) where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([YapItem] -> Void)? = .None) { + Metadata.Coder.Value == Metadata { let items = yapItems(with: metadata) return connection.asyncWriteWithMetadata(items, queue: queue, completion: completion) } @@ -157,13 +157,13 @@ extension SequenceType where - returns: an `NSOperation` */ public func writeWithMetadataOperation< - Connection, Metadata where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?]) -> Operation where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(connection: Connection, metadata: [Metadata?]) -> NSOperation { + Metadata.Coder.Value == Metadata { let items = yapItems(with: metadata) - return NSBlockOperation { connection.writeWithMetadata(items) } + return BlockOperation { connection.writeWithMetadata(items) } } } @@ -173,71 +173,71 @@ extension Readable where ItemType: ValueCoding, ItemType: Persistable, ItemType.Coder: NSCoding, - ItemType.Coder.ValueType == ItemType { + ItemType.Coder.Value == ItemType { func withMetadataInTransaction< - Metadata where + Metadata>(_ transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> YapItem? { + Metadata.Coder.Value == Metadata { return transaction.readWithMetadataAtIndex(index) } func withMetadataInTransactionAtIndex< - Metadata where + Metadata>(_ transaction: Database.Connection.ReadTransaction) -> (YapDB.Index) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> YapItem? { + Metadata.Coder.Value == Metadata { return { self.withMetadataInTransaction(transaction, atIndex: $0) } } func withMetadataAtIndexInTransaction< - Metadata where + Metadata>(_ index: YapDB.Index) -> (Database.Connection.ReadTransaction) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> Database.Connection.ReadTransaction -> YapItem? { + Metadata.Coder.Value == Metadata { return { self.withMetadataInTransaction($0, atIndex: index) } } func withMetadataAtIndexesInTransaction< - Indexes, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [YapItem] { + Metadata.Coder.Value == Metadata { return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } } func withMetadataInTransaction< - Metadata where + Metadata>(_ transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? { + Metadata.Coder.Value == Metadata { return withMetadataInTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } func withMetadataInTransactionByKey< - Metadata where + Metadata>(_ transaction: Database.Connection.ReadTransaction) -> (String) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(transaction: Database.Connection.ReadTransaction) -> String -> YapItem? { + Metadata.Coder.Value == Metadata { return { self.withMetadataInTransaction(transaction, byKey: $0) } } func withMetadataByKeyInTransaction< - Metadata where + Metadata>(_ key: String) -> (Database.Connection.ReadTransaction) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> Database.Connection.ReadTransaction -> YapItem? { + Metadata.Coder.Value == Metadata { return { self.withMetadataInTransaction($0, byKey: key) } } func withMetadataByKeysInTransaction< - Metadata where + Metadata>(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [YapItem] where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [YapItem] { + Metadata.Coder.Value == Metadata { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) @@ -251,10 +251,10 @@ extension Readable where - returns: an optional `ItemType` */ public func withMetadataAtIndex< - Metadata where + Metadata>(_ index: YapDB.Index) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(index: YapDB.Index) -> YapItem? { + Metadata.Coder.Value == Metadata { return sync(withMetadataAtIndexInTransaction(index)) } @@ -265,12 +265,12 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataAtIndexes< - Indexes, Metadata where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, + Indexes, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(indexes: Indexes) -> [YapItem] { + Metadata.Coder.Value == Metadata { return sync(withMetadataAtIndexesInTransaction(indexes)) } @@ -281,10 +281,10 @@ extension Readable where - returns: an optional `ItemType` */ public func withMetadataByKey< - Metadata where + Metadata>(_ key: String) -> YapItem? where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(key: String) -> YapItem? { + Metadata.Coder.Value == Metadata { return sync(withMetadataByKeyInTransaction(key)) } @@ -295,12 +295,12 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataByKeys< - Keys, Metadata where - Keys: SequenceType, - Keys.Generator.Element == String, + Keys, Metadata>(_ keys: Keys) -> [YapItem] where + Keys: Sequence, + Keys.Iterator.Element == String, Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: Keys) -> [YapItem] { + Metadata.Coder.Value == Metadata { return sync(withMetadataByKeysInTransaction(Array(keys))) } @@ -310,10 +310,10 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataAll< - Metadata where + Metadata>() -> [YapItem] where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>() -> [YapItem] { + Metadata.Coder.Value == Metadata { return sync(withMetadataByKeysInTransaction()) } @@ -324,11 +324,11 @@ extension Readable where - returns: a tuple of type `([ItemType], [String])` */ public func withMetadataFilterExisting< - Metadata where + Metadata>(_ keys: [String]) -> (existing: [YapItem], missing: [String]) where Metadata: ValueCoding, Metadata.Coder: NSCoding, - Metadata.Coder.ValueType == Metadata>(keys: [String]) -> (existing: [YapItem], missing: [String]) { - let existingInTransaction: Database.Connection.ReadTransaction -> [YapItem] = withMetadataByKeysInTransaction(keys) + Metadata.Coder.Value == Metadata { + let existingInTransaction: (Database.Connection.ReadTransaction) -> [YapItem] = withMetadataByKeysInTransaction(keys) return sync { transaction -> ([YapItem], [String]) in let existing = existingInTransaction(transaction) let existingKeys = existing.map {keyForPersistable($0.value)} diff --git a/Sources/Read.swift b/Sources/Read.swift index 4af4f59..4ac8e0c 100644 --- a/Sources/Read.swift +++ b/Sources/Read.swift @@ -26,17 +26,17 @@ public struct Read: Readable { let reader: Handle public var transaction: D.Connection.ReadTransaction? { - if case let .Transaction(transaction) = reader { + if case let .transaction(transaction) = reader { return transaction } - return .None + return .none } public var connection: D.Connection { switch reader { - case .Transaction(_): + case .transaction(_): fatalError("Attempting to get connection from a transaction.") - case .Connection(let connection): + case .connection(let connection): return connection default: return database.makeNewConnection() @@ -44,22 +44,22 @@ public struct Read: Readable { } internal var database: D { - if case let .Database(database) = reader { + if case let .database(database) = reader { return database } fatalError("Attempting to get database from \(reader)") } internal init(_ transaction: D.Connection.ReadTransaction) { - reader = .Transaction(transaction) + reader = .transaction(transaction) } internal init(_ connection: D.Connection) { - reader = .Connection(connection) + reader = .connection(connection) } internal init(_ database: D) { - reader = .Database(database) + reader = .database(database) } } @@ -83,7 +83,7 @@ extension Persistable { - parameter transaction: a type conforming to ReadTransactionType such as YapDatabaseReadTransaction */ - public static func read(transaction: D.Connection.ReadTransaction) -> Read { + public static func read(_ transaction: D.Connection.ReadTransaction) -> Read { return Read(transaction) } @@ -105,11 +105,11 @@ extension Persistable { - parameter connection: a type conforming to ConnectionType such as YapDatabaseConnection. */ - public static func read(connection: D.Connection) -> Read { + public static func read(_ connection: D.Connection) -> Read { return Read(connection) } - internal static func read(database: D) -> Read { + internal static func read(_ database: D) -> Read { return Read(database) } } @@ -118,7 +118,7 @@ extension Readable where ItemType: Persistable { - func sync(block: (Database.Connection.ReadTransaction) -> T) -> T { + func sync(_ block: (Database.Connection.ReadTransaction) -> T) -> T { if let transaction = transaction { return block(transaction) } diff --git a/Sources/YapDB.swift b/Sources/YapDB.swift index 7534482..ccd11d3 100644 --- a/Sources/YapDB.swift +++ b/Sources/YapDB.swift @@ -7,8 +7,8 @@ protocol YapDatabaseViewProducer { } protocol YapDatabaseExtensionRegistrar { - func isRegisteredInDatabase(database: YapDatabase) -> Bool - func registerInDatabase(database: YapDatabase, withConnection: YapDatabaseConnection?) + func isRegisteredInDatabase(_ database: YapDatabase) -> Bool + func registerInDatabase(_ database: YapDatabase, withConnection: YapDatabaseConnection?) } extension YapDB { @@ -20,26 +20,26 @@ extension YapDB { */ public enum Fetch: YapDatabaseExtensionRegistrar { - case View(YapDB.View) - case Filter(YapDB.Filter) - case Search(YapDB.SearchResults) - case Index(YapDB.SecondaryIndex) + case view(YapDB.View) + case filter(YapDB.Filter) + case search(YapDB.SearchResults) + case index(YapDB.SecondaryIndex) public var name: String { switch self { - case let .View(view): return view.name - case let .Filter(filter): return filter.name - case let .Search(search): return search.name - case let .Index(index): return index.name + case let .view(view): return view.name + case let .filter(filter): return filter.name + case let .search(search): return search.name + case let .index(index): return index.name } } var registrar: YapDatabaseExtensionRegistrar { switch self { - case let .View(view): return view - case let .Filter(filter): return filter - case let .Search(search): return search - case let .Index(index): return index + case let .view(view): return view + case let .filter(filter): return filter + case let .search(search): return search + case let .index(index): return index } } @@ -49,7 +49,7 @@ extension YapDB { - parameter database: a YapDatabase instance - returns: a Bool */ - public func isRegisteredInDatabase(database: YapDatabase) -> Bool { + public func isRegisteredInDatabase(_ database: YapDatabase) -> Bool { return registrar.isRegisteredInDatabase(database) } @@ -59,7 +59,7 @@ extension YapDB { - parameter database: a YapDatabase instance - parameter connection: an optional YapDatabaseConnection, defaults to .None */ - public func registerInDatabase(database: YapDatabase, withConnection connection: YapDatabaseConnection? = .None) { + public func registerInDatabase(_ database: YapDatabase, withConnection connection: YapDatabaseConnection? = .none) { registrar.registerInDatabase(database, withConnection: connection) } @@ -69,7 +69,7 @@ extension YapDB { - parameter database: a YapDatabase instance - parameter connection: an optional YapDatabaseConnection, defaults to .None */ - public func createViewMappings(mappings: Mappings, inDatabase database: YapDatabase, withConnection connection: YapDatabaseConnection? = .None) -> YapDatabaseViewMappings { + public func createViewMappings(_ mappings: Mappings, inDatabase database: YapDatabase, withConnection connection: YapDatabaseConnection? = .none) -> YapDatabaseViewMappings { registerInDatabase(database, withConnection: connection) return mappings.createMappingsWithViewName(name) } @@ -78,13 +78,13 @@ extension YapDB { extension YapDB { - public class BaseExtension { + open class BaseExtension { let name: String let version: String let collections: Set? let persistent: Bool - init(name n: String, version v: String = "1.0", persistent p: Bool = true, collections c: [String]? = .None) { + init(name n: String, version v: String = "1.0", persistent p: Bool = true, collections c: [String]? = .none) { name = n version = v persistent = p @@ -97,15 +97,15 @@ extension YapDB { - parameter database: a YapDatabase instance - returns: A Bool */ - public func isRegisteredInDatabase(database: YapDatabase) -> Bool { - return (database.registeredExtension(name) as? YapDatabaseView) != .None + open func isRegisteredInDatabase(_ database: YapDatabase) -> Bool { + return (database.registeredExtension(name) as? YapDatabaseView) != .none } } /** The base class for other YapDatabaseView wrapper types. */ - public class BaseView: BaseExtension { + open class BaseView: BaseExtension { var options: YapDatabaseViewOptions { get { @@ -124,7 +124,7 @@ extension YapDB { A wrapper around YapDatabaseView. It can be constructed with a name, which is the name the extension is registered under, a grouping enum type and a sorting enum type. */ - public class View: BaseView, YapDatabaseViewProducer, YapDatabaseExtensionRegistrar { + open class View: BaseView, YapDatabaseViewProducer, YapDatabaseExtensionRegistrar { /** An enum to make creating YapDatabaseViewGrouping easier. E.g. @@ -135,25 +135,25 @@ extension YapDB { */ public enum Grouping { - case ByKey(YapDatabaseViewGroupingWithKeyBlock) - case ByObject(YapDatabaseViewGroupingWithObjectBlock) - case ByMetadata(YapDatabaseViewGroupingWithMetadataBlock) - case ByRow(YapDatabaseViewGroupingWithRowBlock) + case byKey(YapDatabaseViewGroupingWithKeyBlock) + case byObject(YapDatabaseViewGroupingWithObjectBlock) + case byMetadata(YapDatabaseViewGroupingWithMetadataBlock) + case byRow(YapDatabaseViewGroupingWithRowBlock) - func object(withOptions opts: YapDatabaseBlockInvoke? = .None) -> YapDatabaseViewGrouping { + func object(withOptions opts: YapDatabaseBlockInvoke? = .none) -> YapDatabaseViewGrouping { if let opts = opts { switch self { - case let .ByKey(block): return YapDatabaseViewGrouping.withOptions(opts, keyBlock: block) - case let .ByObject(block): return YapDatabaseViewGrouping.withOptions(opts, objectBlock: block) - case let .ByMetadata(block): return YapDatabaseViewGrouping.withOptions(opts, metadataBlock: block) - case let .ByRow(block): return YapDatabaseViewGrouping.withOptions(opts, rowBlock: block) + case let .byKey(block): return YapDatabaseViewGrouping.withOptions(opts, keyBlock: block) + case let .byObject(block): return YapDatabaseViewGrouping.withOptions(opts, objectBlock: block) + case let .byMetadata(block): return YapDatabaseViewGrouping.withOptions(opts, metadataBlock: block) + case let .byRow(block): return YapDatabaseViewGrouping.withOptions(opts, rowBlock: block) } } else { switch self { - case let .ByKey(block): return YapDatabaseViewGrouping.withKeyBlock(block) - case let .ByObject(block): return YapDatabaseViewGrouping.withObjectBlock(block) - case let .ByMetadata(block): return YapDatabaseViewGrouping.withMetadataBlock(block) - case let .ByRow(block): return YapDatabaseViewGrouping.withRowBlock(block) + case let .byKey(block): return YapDatabaseViewGrouping.withKeyBlock(block) + case let .byObject(block): return YapDatabaseViewGrouping.withObjectBlock(block) + case let .byMetadata(block): return YapDatabaseViewGrouping.withMetadataBlock(block) + case let .byRow(block): return YapDatabaseViewGrouping.withRowBlock(block) } } } @@ -163,25 +163,25 @@ extension YapDB { An enum to make creating YapDatabaseViewSorting easier. */ public enum Sorting { - case ByKey(YapDatabaseViewSortingWithKeyBlock) - case ByObject(YapDatabaseViewSortingWithObjectBlock) - case ByMetadata(YapDatabaseViewSortingWithMetadataBlock) - case ByRow(YapDatabaseViewSortingWithRowBlock) + case byKey(YapDatabaseViewSortingWithKeyBlock) + case byObject(YapDatabaseViewSortingWithObjectBlock) + case byMetadata(YapDatabaseViewSortingWithMetadataBlock) + case byRow(YapDatabaseViewSortingWithRowBlock) - func object(withOptions opts: YapDatabaseBlockInvoke? = .None) -> YapDatabaseViewSorting { + func object(withOptions opts: YapDatabaseBlockInvoke? = .none) -> YapDatabaseViewSorting { if let opts = opts { switch self { - case let .ByKey(block): return YapDatabaseViewSorting.withOptions(opts, keyBlock: block) - case let .ByObject(block): return YapDatabaseViewSorting.withOptions(opts, objectBlock: block) - case let .ByMetadata(block): return YapDatabaseViewSorting.withOptions(opts, metadataBlock: block) - case let .ByRow(block): return YapDatabaseViewSorting.withOptions(opts, rowBlock: block) + case let .byKey(block): return YapDatabaseViewSorting.withOptions(opts, keyBlock: block) + case let .byObject(block): return YapDatabaseViewSorting.withOptions(opts, objectBlock: block) + case let .byMetadata(block): return YapDatabaseViewSorting.withOptions(opts, metadataBlock: block) + case let .byRow(block): return YapDatabaseViewSorting.withOptions(opts, rowBlock: block) } } else { switch self { - case let .ByKey(block): return YapDatabaseViewSorting.withKeyBlock(block) - case let .ByObject(block): return YapDatabaseViewSorting.withObjectBlock(block) - case let .ByMetadata(block): return YapDatabaseViewSorting.withMetadataBlock(block) - case let .ByRow(block): return YapDatabaseViewSorting.withRowBlock(block) + case let .byKey(block): return YapDatabaseViewSorting.withKeyBlock(block) + case let .byObject(block): return YapDatabaseViewSorting.withObjectBlock(block) + case let .byMetadata(block): return YapDatabaseViewSorting.withMetadataBlock(block) + case let .byRow(block): return YapDatabaseViewSorting.withRowBlock(block) } } } @@ -203,9 +203,9 @@ extension YapDB { - parameter collections: an optional array of collections which is used to white list the collections searched when populating the view. */ public init(name: String, - grouping g: Grouping, groupingOptions go: YapDatabaseBlockInvoke? = .None, - sorting s: Sorting, sortingOptions so: YapDatabaseBlockInvoke? = .None, - version: String = "1.0", persistent: Bool = true, collections: [String]? = .None) { + grouping g: Grouping, groupingOptions go: YapDatabaseBlockInvoke? = .none, + sorting s: Sorting, sortingOptions so: YapDatabaseBlockInvoke? = .none, + version: String = "1.0", persistent: Bool = true, collections: [String]? = .none) { grouping = g groupingOptions = go sorting = s @@ -217,13 +217,13 @@ extension YapDB { return YapDatabaseView(grouping: grouping.object(withOptions: groupingOptions), sorting: sorting.object(withOptions: sortingOptions), versionTag: version, options: options) } - func registerInDatabase(database: YapDatabase, withConnection connection: YapDatabaseConnection? = .None) { + func registerInDatabase(_ database: YapDatabase, withConnection connection: YapDatabaseConnection? = .none) { if !isRegisteredInDatabase(database) { if let connection = connection { - database.registerExtension(createDatabaseView(), withName: name, connection: connection) + database.register(createDatabaseView(), withName: name, connection: connection) } else { - database.registerExtension(createDatabaseView(), withName: name) + database.register(createDatabaseView(), withName: name) } } } @@ -240,31 +240,31 @@ extension YapDB { is a YapDB.Fetch type. This allows for filtering of other filters, and even filtering of search results. */ - public class Filter: BaseView, YapDatabaseViewProducer, YapDatabaseExtensionRegistrar { + open class Filter: BaseView, YapDatabaseViewProducer, YapDatabaseExtensionRegistrar { /** An enum to make creating YapDatabaseViewFiltering easier. */ public enum Filtering { - case ByKey(YapDatabaseViewFilteringWithKeyBlock) - case ByObject(YapDatabaseViewFilteringWithObjectBlock) - case ByMetadata(YapDatabaseViewFilteringWithMetadataBlock) - case ByRow(YapDatabaseViewFilteringWithRowBlock) + case byKey(YapDatabaseViewFilteringWithKeyBlock) + case byObject(YapDatabaseViewFilteringWithObjectBlock) + case byMetadata(YapDatabaseViewFilteringWithMetadataBlock) + case byRow(YapDatabaseViewFilteringWithRowBlock) - func object(withOptions ops: YapDatabaseBlockInvoke? = .None) -> YapDatabaseViewFiltering { + func object(withOptions ops: YapDatabaseBlockInvoke? = .none) -> YapDatabaseViewFiltering { if let ops = ops { switch self { - case .ByKey(let block): return YapDatabaseViewFiltering.withOptions(ops, keyBlock: block) - case .ByObject(let block): return YapDatabaseViewFiltering.withOptions(ops, objectBlock: block) - case .ByMetadata(let block): return YapDatabaseViewFiltering.withOptions(ops, metadataBlock: block) - case .ByRow(let block): return YapDatabaseViewFiltering.withOptions(ops, rowBlock: block) + case .byKey(let block): return YapDatabaseViewFiltering.withOptions(ops, keyBlock: block) + case .byObject(let block): return YapDatabaseViewFiltering.withOptions(ops, objectBlock: block) + case .byMetadata(let block): return YapDatabaseViewFiltering.withOptions(ops, metadataBlock: block) + case .byRow(let block): return YapDatabaseViewFiltering.withOptions(ops, rowBlock: block) } } else { switch self { - case .ByKey(let block): return YapDatabaseViewFiltering.withKeyBlock(block) - case .ByObject(let block): return YapDatabaseViewFiltering.withObjectBlock(block) - case .ByMetadata(let block): return YapDatabaseViewFiltering.withMetadataBlock(block) - case .ByRow(let block): return YapDatabaseViewFiltering.withRowBlock(block) + case .byKey(let block): return YapDatabaseViewFiltering.withKeyBlock(block) + case .byObject(let block): return YapDatabaseViewFiltering.withObjectBlock(block) + case .byMetadata(let block): return YapDatabaseViewFiltering.withMetadataBlock(block) + case .byRow(let block): return YapDatabaseViewFiltering.withRowBlock(block) } } } @@ -284,8 +284,8 @@ extension YapDB { - parameter persistent: a Bool, defaults to true - meaning that the contents of the view will be stored in YapDatabase between launches. - parameter collections: an optional array of collections which is used to white list the collections searched when populating the view. */ - public init(name: String, parent p: YapDB.Fetch, filtering f: Filtering, filteringOptions fo: YapDatabaseBlockInvoke? = .None, - version: String = "1.0", persistent: Bool = true, collections: [String]? = .None) { + public init(name: String, parent p: YapDB.Fetch, filtering f: Filtering, filteringOptions fo: YapDatabaseBlockInvoke? = .none, + version: String = "1.0", persistent: Bool = true, collections: [String]? = .none) { parent = p filtering = f filteringOptions = fo @@ -296,14 +296,14 @@ extension YapDB { return YapDatabaseFilteredView(parentViewName: parent.name, filtering: filtering.object(withOptions: filteringOptions), versionTag: version, options: options) } - func registerInDatabase(database: YapDatabase, withConnection connection: YapDatabaseConnection? = .None) { + func registerInDatabase(_ database: YapDatabase, withConnection connection: YapDatabaseConnection? = .none) { if !isRegisteredInDatabase(database) { parent.registerInDatabase(database, withConnection: connection) if let connection = connection { - database.registerExtension(createDatabaseView(), withName: name, connection: connection) + database.register(createDatabaseView(), withName: name, connection: connection) } else { - database.registerExtension(createDatabaseView(), withName: name) + database.register(createDatabaseView(), withName: name) } } } @@ -320,23 +320,23 @@ extension YapDB { In this case, the parent is a YapDB.Fetch type. This allows for searching of other filters, and even searching inside search results. */ - public class SearchResults: BaseView, YapDatabaseViewProducer, YapDatabaseExtensionRegistrar { + open class SearchResults: BaseView, YapDatabaseViewProducer, YapDatabaseExtensionRegistrar { /** An enum to make creating YapDatabaseFullTextSearchHandler easier. */ public enum Handler { - case ByKey(YapDatabaseFullTextSearchWithKeyBlock) - case ByObject(YapDatabaseFullTextSearchWithObjectBlock) - case ByMetadata(YapDatabaseFullTextSearchWithMetadataBlock) - case ByRow(YapDatabaseFullTextSearchWithRowBlock) + case byKey(YapDatabaseFullTextSearchWithKeyBlock) + case byObject(YapDatabaseFullTextSearchWithObjectBlock) + case byMetadata(YapDatabaseFullTextSearchWithMetadataBlock) + case byRow(YapDatabaseFullTextSearchWithRowBlock) public var object: YapDatabaseFullTextSearchHandler { switch self { - case let .ByKey(block): return YapDatabaseFullTextSearchHandler.withKeyBlock(block) - case let .ByObject(block): return YapDatabaseFullTextSearchHandler.withObjectBlock(block) - case let .ByMetadata(block): return YapDatabaseFullTextSearchHandler.withMetadataBlock(block) - case let .ByRow(block): return YapDatabaseFullTextSearchHandler.withRowBlock(block) + case let .byKey(block): return YapDatabaseFullTextSearchHandler.withKeyBlock(block) + case let .byObject(block): return YapDatabaseFullTextSearchHandler.withObjectBlock(block) + case let .byMetadata(block): return YapDatabaseFullTextSearchHandler.withMetadataBlock(block) + case let .byRow(block): return YapDatabaseFullTextSearchHandler.withRowBlock(block) } } } @@ -358,7 +358,7 @@ extension YapDB { - parameter persistent: a Bool, defaults to true - meaning that the contents of the view will be stored in YapDatabase between launches. - parameter collections: an optional array of collections which is used to white list the collections searched when populating the view. */ - public init(name: String, parent p: YapDB.Fetch, search: String, columnNames cn: [String], handler h: Handler, version: String = "1.0", persistent: Bool = true, collections: [String]? = .None) { + public init(name: String, parent p: YapDB.Fetch, search: String, columnNames cn: [String], handler h: Handler, version: String = "1.0", persistent: Bool = true, collections: [String]? = .none) { parent = p searchName = search columnNames = cn @@ -367,28 +367,28 @@ extension YapDB { } func createDatabaseView() -> YapDatabaseView { - return YapDatabaseSearchResultsView(fullTextSearchName: searchName, parentViewName: parent.name, versionTag: version, options: .None) + return YapDatabaseSearchResultsView(fullTextSearchName: searchName, parentViewName: parent.name, versionTag: version, options: .none) } - func registerInDatabase(database: YapDatabase, withConnection connection: YapDatabaseConnection? = .None) { + func registerInDatabase(_ database: YapDatabase, withConnection connection: YapDatabaseConnection? = .none) { - if (database.registeredExtension(searchName) as? YapDatabaseFullTextSearch) == .None { + if (database.registeredExtension(searchName) as? YapDatabaseFullTextSearch) == .none { let fullTextSearch = YapDatabaseFullTextSearch(columnNames: columnNames, handler: handler.object, versionTag: version) if let connection = connection { - database.registerExtension(fullTextSearch, withName: searchName, connection: connection) + database.register(fullTextSearch, withName: searchName, connection: connection) } else { - database.registerExtension(fullTextSearch, withName: searchName) + database.register(fullTextSearch, withName: searchName) } } if !isRegisteredInDatabase(database) { parent.registerInDatabase(database, withConnection: connection) if let connection = connection { - database.registerExtension(createDatabaseView(), withName: name, connection: connection) + database.register(createDatabaseView(), withName: name, connection: connection) } else { - database.registerExtension(createDatabaseView(), withName: name) + database.register(createDatabaseView(), withName: name) } } } @@ -405,20 +405,20 @@ extension YapDB { is similar to a full text search extension. It features a handler, which must be provided to update a dictionary used to index records. */ - public class SecondaryIndex: BaseExtension, YapDatabaseExtensionRegistrar { + open class SecondaryIndex: BaseExtension, YapDatabaseExtensionRegistrar { public enum Handler { - case ByKey(YapDatabaseSecondaryIndexWithKeyBlock) - case ByObject(YapDatabaseSecondaryIndexWithObjectBlock) - case ByMetadata(YapDatabaseSecondaryIndexWithMetadataBlock) - case ByRow(YapDatabaseSecondaryIndexWithRowBlock) + case byKey(YapDatabaseSecondaryIndexWithKeyBlock) + case byObject(YapDatabaseSecondaryIndexWithObjectBlock) + case byMetadata(YapDatabaseSecondaryIndexWithMetadataBlock) + case byRow(YapDatabaseSecondaryIndexWithRowBlock) public var object: YapDatabaseSecondaryIndexHandler { switch self { - case let .ByKey(block): return YapDatabaseSecondaryIndexHandler.withKeyBlock(block) - case let .ByObject(block): return YapDatabaseSecondaryIndexHandler.withObjectBlock(block) - case let .ByMetadata(block): return YapDatabaseSecondaryIndexHandler.withMetadataBlock(block) - case let .ByRow(block): return YapDatabaseSecondaryIndexHandler.withRowBlock(block) + case let .byKey(block): return YapDatabaseSecondaryIndexHandler.withKeyBlock(block) + case let .byObject(block): return YapDatabaseSecondaryIndexHandler.withObjectBlock(block) + case let .byMetadata(block): return YapDatabaseSecondaryIndexHandler.withMetadataBlock(block) + case let .byRow(block): return YapDatabaseSecondaryIndexHandler.withRowBlock(block) } } } @@ -443,19 +443,19 @@ extension YapDB { func setup() -> YapDatabaseSecondaryIndexSetup { let setup = YapDatabaseSecondaryIndexSetup() for (column, indexType) in columnTypes { - setup.addColumn(column, withType: indexType) + setup.addColumn(column, with: indexType) } return setup } - public func registerInDatabase(database: YapDatabase, withConnection connection: YapDatabaseConnection?) { + open func registerInDatabase(_ database: YapDatabase, withConnection connection: YapDatabaseConnection?) { if !isRegisteredInDatabase(database) { let secondaryIndex = YapDatabaseSecondaryIndex(setup: setup(), handler: handler.object, versionTag: version, options: options) if let connection = connection { - database.registerExtension(secondaryIndex, withName: name, connection: connection) + database.register(secondaryIndex, withName: name, connection: connection) } else { - database.registerExtension(secondaryIndex, withName: name) + database.register(secondaryIndex, withName: name) } } } @@ -467,9 +467,9 @@ extension YapDB { public struct Mappings { public enum Kind { - case Composed(YapDatabaseViewMappings) - case Groups([String]) - case Dynamic((filter: YapDatabaseViewMappingGroupFilter, sorter: YapDatabaseViewMappingGroupSort)) + case composed(YapDatabaseViewMappings) + case groups([String]) + case dynamic((filter: YapDatabaseViewMappingGroupFilter, sorter: YapDatabaseViewMappingGroupSort)) } public static var passThroughFilter: YapDatabaseViewMappingGroupFilter { @@ -482,25 +482,25 @@ extension YapDB { let kind: Kind - public init(filter f: YapDatabaseViewMappingGroupFilter = Mappings.passThroughFilter, sort s: YapDatabaseViewMappingGroupSort = Mappings.caseInsensitiveGroupSort) { - kind = .Dynamic((f, s)) + public init(filter f: @escaping YapDatabaseViewMappingGroupFilter = Mappings.passThroughFilter, sort s: @escaping YapDatabaseViewMappingGroupSort = Mappings.caseInsensitiveGroupSort) { + kind = .dynamic((f, s)) } public init(groups: [String]) { - kind = .Groups(groups) + kind = .groups(groups) } public init(composed: YapDatabaseViewMappings) { - kind = .Composed(composed) + kind = .composed(composed) } - func createMappingsWithViewName(viewName: String) -> YapDatabaseViewMappings { + func createMappingsWithViewName(_ viewName: String) -> YapDatabaseViewMappings { switch kind { - case .Composed(let mappings): + case .composed(let mappings): return mappings - case .Groups(let groups): + case .groups(let groups): return YapDatabaseViewMappings(groups: groups, view: viewName) - case .Dynamic(let (filter: filter, sorter: sorter)): + case .dynamic(let (filter: filter, sorter: sorter)): return YapDatabaseViewMappings(groupFilterBlock: filter, sortBlock: sorter, view: viewName) } } @@ -521,25 +521,25 @@ extension YapDB { return fetch.name } - public init(fetch f: Fetch, mappings m: Mappings = Mappings(), block b: MappingsConfigurationBlock? = .None) { + public init(fetch f: Fetch, mappings m: Mappings = Mappings(), block b: MappingsConfigurationBlock? = .none) { fetch = f mappings = m block = b } public init(view: YapDB.View) { - self.init(fetch: .View(view)) + self.init(fetch: .view(view)) } public init(filter: YapDB.Filter) { - self.init(fetch: .Filter(filter)) + self.init(fetch: .filter(filter)) } public init(search: YapDB.SearchResults) { - self.init(fetch: .Search(search)) + self.init(fetch: .search(search)) } - public func createMappingsRegisteredInDatabase(database: YapDatabase, withConnection connection: YapDatabaseConnection? = .None) -> YapDatabaseViewMappings { + public func createMappingsRegisteredInDatabase(_ database: YapDatabase, withConnection connection: YapDatabaseConnection? = .none) -> YapDatabaseViewMappings { let databaseViewMappings = fetch.createViewMappings(mappings, inDatabase: database, withConnection: connection) block?(databaseViewMappings) return databaseViewMappings @@ -550,20 +550,20 @@ extension YapDB { extension YapDB { - public class Search { - public typealias Query = (searchTerm: String) -> String + open class Search { + public typealias Query = (_ searchTerm: String) -> String let database: YapDatabase let connection: YapDatabaseConnection let queues: [(String, YapDatabaseSearchQueue)] let query: Query - public init(db: YapDatabase, views: [YapDB.Fetch], query q: Query) { + public init(db: YapDatabase, views: [YapDB.Fetch], query q: @escaping Query) { database = db connection = db.newConnection() let _views = views.filter { fetch in switch fetch { - case .Index(_): return false + case .index(_): return false default: return true } } @@ -574,18 +574,18 @@ extension YapDB { query = q } - public convenience init(db: YapDatabase, view: YapDB.Fetch, query: Query) { + public convenience init(db: YapDatabase, view: YapDB.Fetch, query: @escaping Query) { self.init(db: db, views: [view], query: query) } - public func usingTerm(term: String) { + open func usingTerm(_ term: String) { for (_, queue) in queues { - queue.enqueueQuery(query(searchTerm: term)) + queue.enqueueQuery(query(term)) } - connection.asyncReadWriteWithBlock { [queues = self.queues] transaction in + connection.asyncReadWrite { [queues = self.queues] transaction in for (name, queue) in queues { if let searchResultsViewTransaction = transaction.ext(name) as? YapDatabaseSearchResultsViewTransaction { - searchResultsViewTransaction.performSearchWithQueue(queue) + searchResultsViewTransaction.performSearch(with: queue) } else { assertionFailure("Error: Attempting search using results view with name: \(name) which isn't a registered database extension.") diff --git a/Sources/YapDatabaseExtensions.swift b/Sources/YapDatabaseExtensions.swift index b6cf121..9bddafd 100644 --- a/Sources/YapDatabaseExtensions.swift +++ b/Sources/YapDatabaseExtensions.swift @@ -22,8 +22,8 @@ public struct YapDB { - returns: a String representing the path to a database in the given search directory, with the given name/suffix. */ - public static func pathToDatabase(directory: NSSearchPathDirectory, name: String, suffix: String? = .None) -> String { - let paths = NSSearchPathForDirectoriesInDomains(directory, .UserDomainMask, true) + public static func pathToDatabase(_ directory: FileManager.SearchPathDirectory, name: String, suffix: String? = .none) -> String { + let paths = NSSearchPathForDirectoriesInDomains(directory, .userDomainMask, true) let directory: String = paths.first ?? NSTemporaryDirectory() let filename: String = { if let suffix = suffix { @@ -32,7 +32,7 @@ public struct YapDB { return "\(name).sqlite" }() - return (directory as NSString).stringByAppendingPathComponent(filename) + return (directory as NSString).appendingPathComponent(filename) } /// Type of closure which can perform operations on newly created/opened database instances. @@ -73,8 +73,8 @@ public struct YapDB { - returns: the YapDatabase instance. */ - public static func databaseNamed(name: String, operations: DatabaseOperationsBlock? = .None) -> YapDatabase { - let db = YapDatabase(path: pathToDatabase(.DocumentDirectory, name: name, suffix: .None)) + public static func databaseNamed(_ name: String, operations: DatabaseOperationsBlock? = .none) -> YapDatabase { + let db = YapDatabase(path: pathToDatabase(.documentDirectory, name: name, suffix: .none)) operations?(db) return db } @@ -105,11 +105,11 @@ public struct YapDB { - returns: the YapDatabase instance. */ - public static func testDatabase(file: String = #file, test: String = #function, operations: DatabaseOperationsBlock? = .None) -> YapDatabase { - let path = pathToDatabase(.CachesDirectory, name: (file as NSString).lastPathComponent, suffix: test.stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "()"))) + public static func testDatabase(_ file: String = #file, test: String = #function, operations: DatabaseOperationsBlock? = .none) -> YapDatabase { + let path = pathToDatabase(.cachesDirectory, name: (file as NSString).lastPathComponent, suffix: test.trimmingCharacters(in: CharacterSet(charactersIn: "()"))) assert(!path.isEmpty, "Path should not be empty.") do { - try NSFileManager.defaultManager().removeItemAtPath(path) + try FileManager.default.removeItem(atPath: path) } catch { } @@ -219,7 +219,7 @@ extension Persistable { - parameter key: a `String` - returns: a `YapDB.Index` value. */ - public static func indexWithKey(key: String) -> YapDB.Index { + public static func indexWithKey(_ key: String) -> YapDB.Index { return YapDB.Index(collection: collection, key: key) } @@ -234,9 +234,9 @@ extension Persistable { - returns: an array of `YapDB.Index` values. */ public static func indexesWithKeys< - Keys where - Keys: SequenceType, - Keys.Generator.Element == String>(keys: Keys) -> [YapDB.Index] { + Keys>(_ keys: Keys) -> [YapDB.Index] where + Keys: Sequence, + Keys.Iterator.Element == String { return Set(keys).map { YapDB.Index(collection: collection, key: $0) } } @@ -256,17 +256,17 @@ extension Persistable { - returns: a `YapDB.Index`. */ public var index: YapDB.Index { - return self.dynamicType.indexWithKey(key) + return type(of: self).indexWithKey(key) } } // MARK: Functions -public func keyForPersistable(persistable: P) -> String { +public func keyForPersistable(_ persistable: P) -> String { return persistable.key } -public func indexForPersistable(persistable: P) -> YapDB.Index { +public func indexForPersistable(_ persistable: P) -> YapDB.Index { return persistable.index } @@ -281,7 +281,7 @@ public protocol ReadTransactionType { - parameter collection: a String. Not optional. - returns: an array of String values. */ - func keysInCollection(collection: String) -> [String] + func keysInCollection(_ collection: String) -> [String] /** Read the object at the index. @@ -289,7 +289,7 @@ public protocol ReadTransactionType { - parameter index: a YapDB.Index. - returns: an `AnyObject` if an item existing in the database for this index. */ - func readAtIndex(index: YapDB.Index) -> AnyObject? + func readAtIndex(_ index: YapDB.Index) -> AnyObject? /** Read the metadata at the index. @@ -297,7 +297,7 @@ public protocol ReadTransactionType { - parameter index: a YapDB.Index. - returns: an `AnyObject` if a metadata item existing in the database for this index. */ - func readMetadataAtIndex(index: YapDB.Index) -> AnyObject? + func readMetadataAtIndex(_ index: YapDB.Index) -> AnyObject? } /// A facade interface for a write transaction. @@ -310,7 +310,7 @@ public protocol WriteTransactionType: ReadTransactionType { - parameter object: the `AnyObject` which will be written. - parameter metadata: an optional `AnyObject` which will be written as metadata. */ - func writeAtIndex(index: YapDB.Index, object: AnyObject, metadata: AnyObject?) + func writeAtIndex(_ index: YapDB.Index, object: AnyObject, metadata: AnyObject?) /** Remove the sequence object from the database at the indexes (if it exists), including metadata @@ -318,9 +318,9 @@ public protocol WriteTransactionType: ReadTransactionType { - parameter indexes: the `[YapDB.Index]` to remove. */ func removeAtIndexes< - Indexes where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) + Indexes>(_ indexes: Indexes) where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index } /// A facade interface for a database connection. @@ -339,7 +339,7 @@ public protocol ConnectionType { - parameter block: a closure which receives YapDatabaseReadTransaction and returns T - returns: An instance of T */ - func read(block: ReadTransaction -> T) -> T + func read(_ block: (ReadTransaction) -> T) -> T /** Synchronously writes to the database on the connection. The closure receives @@ -352,7 +352,7 @@ public protocol ConnectionType { - parameter block: a closure which receives YapDatabaseReadWriteTransaction and returns T - returns: An instance of T */ - func write(block: WriteTransaction -> T) -> T + func write(_ block: (WriteTransaction) -> T) -> T /** Asynchronously reads from the database on the connection. The closure receives @@ -368,7 +368,7 @@ public protocol ConnectionType { - parameter queue: a dispatch_queue_t, defaults to main queue, can be ommitted in most cases. - parameter completion: a closure which receives T and returns Void. */ - func asyncRead(block: ReadTransaction -> T, queue: dispatch_queue_t, completion: (T) -> Void) + func asyncRead(_ block: (ReadTransaction) -> T, queue: DispatchQueue, completion: (T) -> Void) /** Asynchronously writes to the database on the connection. The closure receives @@ -384,7 +384,7 @@ public protocol ConnectionType { - parameter queue: a dispatch_queue_t, defaults to main queue, can be ommitted in most cases. - parameter completion: a closure which receives T and returns Void. */ - func asyncWrite(block: WriteTransaction -> T, queue: dispatch_queue_t, completion: (T -> Void)?) + func asyncWrite(_ block: (WriteTransaction) -> T, queue: DispatchQueue, completion: ((T) -> Void)?) /** Execute a read/write block inside a `NSOperation`. The block argument receives a @@ -400,7 +400,7 @@ public protocol ConnectionType { - parameter block: a closure of type (YapDatabaseReadWriteTransaction) -> Void - returns: an `NSOperation`. */ - func writeBlockOperation(block: WriteTransaction -> Void) -> NSOperation + func writeBlockOperation(_ block: (WriteTransaction) -> Void) -> Operation } /// A facade interface for a database. @@ -410,9 +410,9 @@ public protocol DatabaseType { } internal enum Handle { - case Transaction(D.Connection.ReadTransaction) - case Connection(D.Connection) - case Database(D) + case transaction(D.Connection.ReadTransaction) + case connection(D.Connection) + case database(D) } // MARK: - YapDatabaseReadTransaction @@ -425,8 +425,8 @@ extension YapDatabaseReadTransaction: ReadTransactionType { - parameter collection: a String. - returns: an array of String values. */ - public func keysInCollection(collection: String) -> [String] { - return allKeysInCollection(collection) + public func keysInCollection(_ collection: String) -> [String] { + return allKeys(inCollection: collection) } /** @@ -435,8 +435,8 @@ extension YapDatabaseReadTransaction: ReadTransactionType { - parameter index: The YapDB.Index value. - returns: An optional AnyObject. */ - public func readAtIndex(index: YapDB.Index) -> AnyObject? { - return objectForKey(index.key, inCollection: index.collection) + public func readAtIndex(_ index: YapDB.Index) -> AnyObject? { + return object(forKey: index.key, inCollection: index.collection) as AnyObject? } /** @@ -445,8 +445,8 @@ extension YapDatabaseReadTransaction: ReadTransactionType { - parameter index: The YapDB.Index value. - returns: An optional AnyObject. */ - public func readMetadataAtIndex(index: YapDB.Index) -> AnyObject? { - return metadataForKey(index.key, inCollection: index.collection) + public func readMetadataAtIndex(_ index: YapDB.Index) -> AnyObject? { + return metadata(forKey: index.key, inCollection: index.collection) as AnyObject? } } @@ -454,7 +454,7 @@ extension YapDatabaseReadTransaction: ReadTransactionType { extension YapDatabaseReadWriteTransaction: WriteTransactionType { - public func writeAtIndex(index: YapDB.Index, object: AnyObject, metadata: AnyObject? = .None) { + public func writeAtIndex(_ index: YapDB.Index, object: AnyObject, metadata: AnyObject? = .none) { if let metadata: AnyObject = metadata { setObject(object, forKey: index.key, inCollection: index.collection, withMetadata: metadata) } @@ -463,14 +463,14 @@ extension YapDatabaseReadWriteTransaction: WriteTransactionType { } } - func removeAtIndex(index: YapDB.Index) { - removeObjectForKey(index.key, inCollection: index.collection) + func removeAtIndex(_ index: YapDB.Index) { + removeObject(forKey: index.key, inCollection: index.collection) } public func removeAtIndexes< - Indexes where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) { + Indexes>(_ indexes: Indexes) where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index { indexes.forEach(removeAtIndex) } } @@ -488,9 +488,9 @@ extension YapDatabaseConnection: ConnectionType { - parameter block: a closure which receives YapDatabaseReadTransaction and returns T - returns: An instance of T */ - public func read(block: YapDatabaseReadTransaction -> T) -> T { - var result: T! = .None - readWithBlock { result = block($0) } + public func read(_ block: @escaping (YapDatabaseReadTransaction) -> T) -> T { + var result: T! = .none + self.read { result = block($0) } return result } @@ -505,9 +505,9 @@ extension YapDatabaseConnection: ConnectionType { - parameter block: a closure which receives YapDatabaseReadWriteTransaction and returns T - returns: An instance of T */ - public func write(block: YapDatabaseReadWriteTransaction -> T) -> T { - var result: T! = .None - readWriteWithBlock { result = block($0) } + public func write(_ block: @escaping (YapDatabaseReadWriteTransaction) -> T) -> T { + var result: T! = .none + readWrite { result = block($0) } return result } @@ -525,9 +525,9 @@ extension YapDatabaseConnection: ConnectionType { - parameter queue: a dispatch_queue_t, defaults to main queue, can be ommitted in most cases. - parameter completion: a closure which receives T and returns Void. */ - public func asyncRead(block: YapDatabaseReadTransaction -> T, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (T) -> Void) { - var result: T! = .None - asyncReadWithBlock({ result = block($0) }, completionQueue: queue) { completion(result) } + public func asyncRead(_ block: @escaping (YapDatabaseReadTransaction) -> T, queue: DispatchQueue = DispatchQueue.main, completion: @escaping (T) -> Void) { + var result: T! = .none + self.asyncRead({ result = block($0) }, completionQueue: queue) { completion(result) } } /** @@ -544,9 +544,9 @@ extension YapDatabaseConnection: ConnectionType { - parameter queue: a dispatch_queue_t, defaults to main queue, can be ommitted in most cases. - parameter completion: a closure which receives T and returns Void. */ - public func asyncWrite(block: YapDatabaseReadWriteTransaction -> T, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (T -> Void)?) { - var result: T! = .None - asyncReadWriteWithBlock({ result = block($0) }, completionQueue: queue) { completion?(result) } + public func asyncWrite(_ block: @escaping (YapDatabaseReadWriteTransaction) -> T, queue: DispatchQueue = DispatchQueue.main, completion: ((T) -> Void)?) { + var result: T! = .none + asyncReadWrite({ result = block($0) }, completionQueue: queue) { completion?(result) } } /** @@ -563,8 +563,8 @@ extension YapDatabaseConnection: ConnectionType { - parameter block: a closure of type (YapDatabaseReadWriteTransaction) -> Void - returns: an `NSOperation`. */ - public func writeBlockOperation(block: (YapDatabaseReadWriteTransaction) -> Void) -> NSOperation { - return NSBlockOperation { self.readWriteWithBlock(block) } + public func writeBlockOperation(_ block: @escaping (YapDatabaseReadWriteTransaction) -> Void) -> Operation { + return BlockOperation { self.readWrite(block) } } } @@ -615,32 +615,32 @@ public final class YapDBIndexCoder: NSObject, NSCoding, CodingType { } public required init(coder aDecoder: NSCoder) { - let collection = aDecoder.decodeObjectForKey("collection") as! String - let key = aDecoder.decodeObjectForKey("key") as! String + let collection = aDecoder.decodeObject(forKey: "collection") as! String + let key = aDecoder.decodeObject(forKey: "key") as! String value = YapDB.Index(collection: collection, key: key) } - public func encodeWithCoder(aCoder: NSCoder) { - aCoder.encodeObject(value.collection, forKey: "collection") - aCoder.encodeObject(value.key, forKey: "key") + public func encode(with aCoder: NSCoder) { + aCoder.encode(value.collection, forKey: "collection") + aCoder.encode(value.key, forKey: "key") } } // MARK: - Deprecations -@available(*, unavailable, renamed="Persistable") +@available(*, unavailable, renamed: "Persistable") public typealias MetadataPersistable = Persistable -@available(*, unavailable, renamed="Persistable") +@available(*, unavailable, renamed: "Persistable") public typealias ObjectMetadataPersistable = Persistable -@available(*, unavailable, renamed="Persistable") +@available(*, unavailable, renamed: "Persistable") public typealias ValueMetadataPersistable = Persistable -@available(*, unavailable, renamed="ValueCoding") +@available(*, unavailable, renamed: "ValueCoding") public typealias Saveable = ValueCoding -@available(*, unavailable, renamed="CodingType") +@available(*, unavailable, renamed: "CodingType") public typealias Archiver = CodingType diff --git a/Tests/Models.swift b/Tests/Models.swift index 22a2efa..f161786 100644 --- a/Tests/Models.swift +++ b/Tests/Models.swift @@ -12,8 +12,8 @@ import YapDatabase import YapDatabaseExtensions public enum Barcode: Equatable { - case UPCA(Int, Int, Int, Int) - case QRCode(String) + case upca(Int, Int, Int, Int) + case qrCode(String) } public struct Product: Identifiable, Equatable { @@ -50,10 +50,10 @@ public struct Inventory: Identifiable, Equatable { } } -public class NamedEntity: NSObject, NSCoding { +open class NamedEntity: NSObject, NSCoding { - public let identifier: Identifier - public let name: String + open let identifier: Identifier + open let name: String public init(id: String, name n: String) { identifier = id @@ -62,21 +62,21 @@ public class NamedEntity: NSObject, NSCoding { public required init?(coder aDecoder: NSCoder) { identifier = aDecoder.decodeObjectForKey("identifier") as! Identifier - name = aDecoder.decodeObjectForKey("name") as! String + name = aDecoder.decodeObject(forKey: "name") as! String } - public func encodeWithCoder(aCoder: NSCoder) { + open func encode(with aCoder: NSCoder) { aCoder.encodeObject(identifier, forKey: "identifier") - aCoder.encodeObject(name, forKey: "name") + aCoder.encode(name, forKey: "name") } } -public class Person: NamedEntity { } +open class Person: NamedEntity { } -public class Employee: NamedEntity { +open class Employee: NamedEntity { } -public class Manager: NamedEntity { +open class Manager: NamedEntity { public struct Metadata: Equatable { public let numberOfDirectReports: Int } @@ -86,9 +86,9 @@ public class Manager: NamedEntity { public func == (a: Barcode, b: Barcode) -> Bool { switch (a, b) { - case let (.UPCA(aNS, aM, aP, aC), .UPCA(bNS, bM, bP, bC)): + case let (.upca(aNS, aM, aP, aC), .upca(bNS, bM, bP, bC)): return (aNS == bNS) && (aM == bM) && (aP == bP) && (aC == bC) - case let (.QRCode(aCode), .QRCode(bCode)): + case let (.qrCode(aCode), .qrCode(bCode)): return aCode == bCode default: return false @@ -149,7 +149,7 @@ extension Manager.Metadata: Hashable { extension NamedEntity { - public override var description: String { + open override var description: String { return "id: \(identifier), name: \(name)" } } @@ -164,9 +164,9 @@ extension Barcode: Persistable { public var identifier: Int { switch self { - case let .UPCA(numberSystem, manufacturer, product, check): + case let .upca(numberSystem, manufacturer, product, check): return "\(numberSystem).\(manufacturer).\(product).\(check)".hashValue - case let .QRCode(code): + case let .qrCode(code): return code.hashValue } } @@ -220,12 +220,12 @@ extension Manager: Persistable { extension Barcode: ValueCoding { public typealias Coder = BarcodeCoder - enum Kind: Int { case UPCA = 1, QRCode } + enum Kind: Int { case upca = 1, qrCode } var kind: Kind { switch self { - case UPCA(_): return Kind.UPCA - case QRCode(_): return Kind.QRCode + case .upca(_): return Kind.upca + case .qrCode(_): return Kind.qrCode } } } @@ -253,25 +253,25 @@ extension Manager.Metadata: ValueCoding { // MARK: - Coders -public class BarcodeCoder: NSObject, NSCoding, CodingType { - public let value: Barcode +open class BarcodeCoder: NSObject, NSCoding, CodingType { + open let value: Barcode public required init(_ v: Barcode) { value = v } public required init?(coder aDecoder: NSCoder) { - if let kind = Barcode.Kind(rawValue: aDecoder.decodeIntegerForKey("kind")) { + if let kind = Barcode.Kind(rawValue: aDecoder.decodeInteger(forKey: "kind")) { switch kind { - case .UPCA: - let numberSystem = aDecoder.decodeIntegerForKey("numberSystem") - let manufacturer = aDecoder.decodeIntegerForKey("manufacturer") - let product = aDecoder.decodeIntegerForKey("product") - let check = aDecoder.decodeIntegerForKey("check") - value = .UPCA(numberSystem, manufacturer, product, check) - case .QRCode: - let code = aDecoder.decodeObjectForKey("code") as! String - value = .QRCode(code) + case .upca: + let numberSystem = aDecoder.decodeInteger(forKey: "numberSystem") + let manufacturer = aDecoder.decodeInteger(forKey: "manufacturer") + let product = aDecoder.decodeInteger(forKey: "product") + let check = aDecoder.decodeInteger(forKey: "check") + value = .upca(numberSystem, manufacturer, product, check) + case .qrCode: + let code = aDecoder.decodeObject(forKey: "code") as! String + value = .qrCode(code) } } else { @@ -279,79 +279,79 @@ public class BarcodeCoder: NSObject, NSCoding, CodingType { } } - public func encodeWithCoder(aCoder: NSCoder) { - aCoder.encodeInteger(value.kind.rawValue, forKey: "kind") + open func encode(with aCoder: NSCoder) { + aCoder.encode(value.kind.rawValue, forKey: "kind") switch value { - case let .UPCA(numberSystem, manufacturer, product, check): - aCoder.encodeInteger(numberSystem, forKey: "numberSystem") - aCoder.encodeInteger(manufacturer, forKey: "manufacturer") - aCoder.encodeInteger(product, forKey: "product") - aCoder.encodeInteger(check, forKey: "check") - case let .QRCode(code): - aCoder.encodeObject(code, forKey: "code") + case let .upca(numberSystem, manufacturer, product, check): + aCoder.encode(numberSystem, forKey: "numberSystem") + aCoder.encode(manufacturer, forKey: "manufacturer") + aCoder.encode(product, forKey: "product") + aCoder.encode(check, forKey: "check") + case let .qrCode(code): + aCoder.encode(code, forKey: "code") } } } -public class ProductCategoryCoder: NSObject, NSCoding, CodingType { - public let value: Product.Category +open class ProductCategoryCoder: NSObject, NSCoding, CodingType { + open let value: Product.Category public required init(_ v: Product.Category) { value = v } public required init?(coder aDecoder: NSCoder) { - let identifier = aDecoder.decodeIntegerForKey("identifier") - let name = aDecoder.decodeObjectForKey("name") as? String + let identifier = aDecoder.decodeInteger(forKey: "identifier") + let name = aDecoder.decodeObject(forKey: "name") as? String value = Product.Category(identifier: identifier, name: name!) } - public func encodeWithCoder(aCoder: NSCoder) { - aCoder.encodeInteger(value.identifier, forKey: "identifier") - aCoder.encodeObject(value.name, forKey: "name") + open func encode(with aCoder: NSCoder) { + aCoder.encode(value.identifier, forKey: "identifier") + aCoder.encode(value.name, forKey: "name") } } -public class ProductMetadataCoder: NSObject, NSCoding, CodingType { - public let value: Product.Metadata +open class ProductMetadataCoder: NSObject, NSCoding, CodingType { + open let value: Product.Metadata public required init(_ v: Product.Metadata) { value = v } public required init?(coder aDecoder: NSCoder) { - let categoryIdentifier = aDecoder.decodeIntegerForKey("categoryIdentifier") + let categoryIdentifier = aDecoder.decodeInteger(forKey: "categoryIdentifier") value = Product.Metadata(categoryIdentifier: categoryIdentifier) } - public func encodeWithCoder(aCoder: NSCoder) { - aCoder.encodeInteger(value.categoryIdentifier, forKey: "categoryIdentifier") + open func encode(with aCoder: NSCoder) { + aCoder.encode(value.categoryIdentifier, forKey: "categoryIdentifier") } } -public class ProductCoder: NSObject, NSCoding, CodingType { - public let value: Product +open class ProductCoder: NSObject, NSCoding, CodingType { + open let value: Product public required init(_ v: Product) { value = v } public required init?(coder aDecoder: NSCoder) { - let identifier = aDecoder.decodeObjectForKey("identifier") as! String - let name = aDecoder.decodeObjectForKey("name") as! String + let identifier = aDecoder.decodeObject(forKey: "identifier") as! String + let name = aDecoder.decodeObject(forKey: "name") as! String let barcode = Barcode.decode(aDecoder.decodeObjectForKey("barcode")) value = Product(identifier: identifier, name: name, barcode: barcode!) } - public func encodeWithCoder(aCoder: NSCoder) { + open func encode(with aCoder: NSCoder) { aCoder.encodeObject(value.identifier, forKey: "identifier") - aCoder.encodeObject(value.name, forKey: "name") + aCoder.encode(value.name, forKey: "name") aCoder.encodeObject(value.barcode.encoded, forKey: "barcode") } } -public class InventoryCoder: NSObject, NSCoding, CodingType { - public let value: Inventory +open class InventoryCoder: NSObject, NSCoding, CodingType { + open let value: Inventory public required init(_ v: Inventory) { value = v @@ -362,26 +362,26 @@ public class InventoryCoder: NSObject, NSCoding, CodingType { value = Inventory(product: product!) } - public func encodeWithCoder(aCoder: NSCoder) { + open func encode(with aCoder: NSCoder) { aCoder.encodeObject(value.product.encoded, forKey: "product") } } -public class ManagerMetadataCoder: NSObject, NSCoding, CodingType { - public let value: Manager.Metadata +open class ManagerMetadataCoder: NSObject, NSCoding, CodingType { + open let value: Manager.Metadata public required init(_ v: Manager.Metadata) { value = v } public required init?(coder aDecoder: NSCoder) { - let numberOfDirectReports = aDecoder.decodeIntegerForKey("numberOfDirectReports") + let numberOfDirectReports = aDecoder.decodeInteger(forKey: "numberOfDirectReports") value = Manager.Metadata(numberOfDirectReports: numberOfDirectReports) } - public func encodeWithCoder(aCoder: NSCoder) { - aCoder.encodeInteger(value.numberOfDirectReports, forKey: "numberOfDirectReports") + open func encode(with aCoder: NSCoder) { + aCoder.encode(value.numberOfDirectReports, forKey: "numberOfDirectReports") } } diff --git a/Tests/ObjectWithNoMetadataTests.swift b/Tests/ObjectWithNoMetadataTests.swift index 5c125d6..158f10d 100644 --- a/Tests/ObjectWithNoMetadataTests.swift +++ b/Tests/ObjectWithNoMetadataTests.swift @@ -29,8 +29,8 @@ class ObjectWithNoMetadataTests: XCTestCase { var reader: Read! - var dispatchQueue: dispatch_queue_t! - var operationQueue: NSOperationQueue! + var dispatchQueue: DispatchQueue! + var operationQueue: OperationQueue! override func setUp() { super.setUp() @@ -50,8 +50,8 @@ class ObjectWithNoMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0) - operationQueue = NSOperationQueue() + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + operationQueue = OperationQueue() } override func tearDown() { @@ -90,7 +90,7 @@ class ObjectWithNoMetadataTests: XCTestCase { readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: TypeUnderTest) { + func checkTransactionDidWriteItem(_ result: TypeUnderTest) { XCTAssertEqual(result.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) @@ -98,7 +98,7 @@ class ObjectWithNoMetadataTests: XCTestCase { XCTAssertNil(writeTransaction.didWriteAtIndexes[0].2) } - func checkTransactionDidWriteItems(result: [TypeUnderTest]) { + func checkTransactionDidWriteItems(_ result: [TypeUnderTest]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) @@ -106,7 +106,7 @@ class ObjectWithNoMetadataTests: XCTestCase { XCTAssertEqual(Set(result), Set(items)) } - func checkTransactionDidReadItem(result: TypeUnderTest?) -> Bool { + func checkTransactionDidReadItem(_ result: TypeUnderTest?) -> Bool { guard let result = result else { return false } @@ -115,7 +115,7 @@ class ObjectWithNoMetadataTests: XCTestCase { return true } - func checkTransactionDidReadItems(result: [TypeUnderTest]) -> Bool { + func checkTransactionDidReadItems(_ result: [TypeUnderTest]) -> Bool { if result.isEmpty { return false } @@ -287,24 +287,24 @@ class Functional_Write_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { func test__connection__async_write_item() { var result: TypeUnderTest! - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") connection.asyncWrite(item) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItem(result) XCTAssertTrue(connection.didAsyncWrite) } func test__connection__async_write_items() { var result: [TypeUnderTest] = [] - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") connection.asyncWrite(items) { received in result = received expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItems(result) XCTAssertTrue(connection.didAsyncWrite) } @@ -339,23 +339,23 @@ class Functional_Remove_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { } func test__connection_async_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() connection.asyncRemove(item) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_async_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() connection.asyncRemove(items) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didAsyncWrite) } @@ -651,20 +651,20 @@ class Persistable_Write_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { } func test__item_persistable__write_async_using_connection() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") var result: TypeUnderTest! = nil item.asyncWrite(connection) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItem(result) XCTAssertTrue(connection.didAsyncWrite) } func test__item_persistable__write_using_opertion() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") let operation = item.writeOperation(connection) operation.completionBlock = { @@ -672,7 +672,7 @@ class Persistable_Write_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) @@ -690,20 +690,20 @@ class Persistable_Write_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { } func test__items_persistable__write_async_using_connection() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") var result: [TypeUnderTest] = [] items.asyncWrite(connection) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItems(result) XCTAssertTrue(connection.didAsyncWrite) } func test__items_persistable__write_using_opertion() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") let operation = items.writeOperation(connection) operation.completionBlock = { @@ -711,7 +711,7 @@ class Persistable_Write_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) @@ -735,25 +735,25 @@ class Persistable_Remove_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { } func test__connection_async_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() item.asyncRemove(connection) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_operation_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() let operation = item.removeOperation(connection) operation.completionBlock = { expectation.fulfill() } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didWrite) } @@ -773,25 +773,25 @@ class Persistable_Remove_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { } func test__connection_async_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() items.asyncRemove(connection) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_operation_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() let operation = items.removeOperation(connection) operation.completionBlock = { expectation.fulfill() } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didWrite) } diff --git a/Tests/ObjectWithObjectMetadataTests.swift b/Tests/ObjectWithObjectMetadataTests.swift index ea690a2..878f782 100644 --- a/Tests/ObjectWithObjectMetadataTests.swift +++ b/Tests/ObjectWithObjectMetadataTests.swift @@ -13,7 +13,7 @@ import XCTest class ObjectWithObjectMetadataTests: XCTestCase { typealias TypeUnderTest = Employee - typealias MetadataTypeUnderTest = NSDate + typealias MetadataTypeUnderTest = Date var item: TypeUnderTest! var metadata: MetadataTypeUnderTest! @@ -32,8 +32,8 @@ class ObjectWithObjectMetadataTests: XCTestCase { var reader: Read! - var dispatchQueue: dispatch_queue_t! - var operationQueue: NSOperationQueue! + var dispatchQueue: DispatchQueue! + var operationQueue: OperationQueue! override func setUp() { super.setUp() @@ -53,8 +53,8 @@ class ObjectWithObjectMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0) - operationQueue = NSOperationQueue() + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + operationQueue = OperationQueue() } override func tearDown() { @@ -78,7 +78,7 @@ class ObjectWithObjectMetadataTests: XCTestCase { func createPersistables() { item = TypeUnderTest(id: "beatle-1", name: "John") - metadata = NSDate() + metadata = Date() items = [ item, TypeUnderTest(id: "beatle-2", name: "Paul"), @@ -86,12 +86,12 @@ class ObjectWithObjectMetadataTests: XCTestCase { TypeUnderTest(id: "beatle-4", name: "Ringo") ] metadatas = [metadata] - items.suffixFrom(1).forEach { _ in metadatas.append(NSDate()) } + items.suffix(from: 1).forEach { _ in metadatas.append(Date()) } } func configureForReadingSingle() { readTransaction.object = item - readTransaction.metadata = metadata + readTransaction.metadata = metadata as AnyObject? } func configureForReadingMultiple() { @@ -100,15 +100,15 @@ class ObjectWithObjectMetadataTests: XCTestCase { readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: YapItem) { + func checkTransactionDidWriteItem(_ result: YapItem) { XCTAssertEqual(result.value.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSDate, metadata) + XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? Date, metadata) } - func checkTransactionDidWriteItems(result: [YapItem]) { + func checkTransactionDidWriteItems(_ result: [YapItem]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) @@ -116,7 +116,7 @@ class ObjectWithObjectMetadataTests: XCTestCase { XCTAssertEqual(Set(result.map({$0.value})), Set(items)) } - func checkTransactionDidReadItem(result: YapItem?) -> Bool { + func checkTransactionDidReadItem(_ result: YapItem?) -> Bool { guard let result = result else { return false } @@ -127,7 +127,7 @@ class ObjectWithObjectMetadataTests: XCTestCase { return true } - func checkTransactionDidReadItems(result: [YapItem]) -> Bool { + func checkTransactionDidReadItems(_ result: [YapItem]) -> Bool { if result.isEmpty { return false } @@ -299,24 +299,24 @@ class Functional_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe func test__connection__async_write_item() { var result: YapItem! - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") connection.asyncWriteWithMetadata(YapItem(item, metadata)) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItem(result) XCTAssertTrue(connection.didAsyncWrite) } func test__connection__async_write_items() { var result: [YapItem] = [] - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") connection.asyncWriteWithMetadata(items.yapItems(with: metadatas)) { received in result = received expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItems(result) XCTAssertTrue(connection.didAsyncWrite) } @@ -351,23 +351,23 @@ class Functional_Remove_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataT } func test__connection_async_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() connection.asyncRemove(item) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_async_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() connection.asyncRemove(items) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didAsyncWrite) } @@ -443,14 +443,14 @@ class Persistable_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe func test__reader__in_transaction_at_index_2() { configureForReadingSingle() reader = Read(readTransaction) - let atIndex: YapDB.Index -> YapItem? = reader.withMetadataInTransactionAtIndex(readTransaction) + let atIndex: (YapDB.Index) -> YapItem? = reader.withMetadataInTransactionAtIndex(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(atIndex(index))) } func test__reader__at_index_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataAtIndexInTransaction(index) + let inTransaction: (TestableReadTransaction) -> YapItem? = reader.withMetadataAtIndexInTransaction(index) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -474,14 +474,14 @@ class Persistable_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe func test__reader__in_transaction_by_key_2() { configureForReadingSingle() reader = Read(readTransaction) - let byKey: String -> YapItem? = reader.withMetadataInTransactionByKey(readTransaction) + let byKey: (String) -> YapItem? = reader.withMetadataInTransactionByKey(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(byKey(key))) } func test__reader__by_key_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataByKeyInTransaction(key) + let inTransaction: (TestableReadTransaction) -> YapItem? = reader.withMetadataByKeyInTransaction(key) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -663,20 +663,20 @@ class Persistable_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataT } func test__item_persistable__write_async_using_connection() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") var result: YapItem! = nil item.asyncWriteWithMetadata(connection, metadata: metadata) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItem(result) XCTAssertTrue(connection.didAsyncWrite) } func test__item_persistable__write_using_opertion() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") let operation = item.writeWithMetadataOperation(connection, metadata: metadata) operation.completionBlock = { @@ -684,11 +684,11 @@ class Persistable_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataT } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSDate, metadata) + XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? Date, metadata) XCTAssertTrue(connection.didWrite) } @@ -702,20 +702,20 @@ class Persistable_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataT } func test__items_persistable__write_async_using_connection() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") var result: [YapItem] = [] items.asyncWriteWithMetadata(connection, metadata: metadatas) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItems(result) XCTAssertTrue(connection.didAsyncWrite) } func test__items_persistable__write_using_opertion() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") let operation = items.writeOperation(connection) operation.completionBlock = { @@ -723,7 +723,7 @@ class Persistable_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataT } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) @@ -747,25 +747,25 @@ class Persistable_Remove_ObjectWithObjectMetadataTests: ObjectWithObjectMetadata } func test__connection_async_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() item.asyncRemove(connection) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_operation_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() let operation = item.removeOperation(connection) operation.completionBlock = { expectation.fulfill() } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didWrite) } @@ -785,25 +785,25 @@ class Persistable_Remove_ObjectWithObjectMetadataTests: ObjectWithObjectMetadata } func test__connection_async_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() items.asyncRemove(connection) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_operation_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() let operation = items.removeOperation(connection) operation.completionBlock = { expectation.fulfill() } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didWrite) } diff --git a/Tests/ObjectWithValueMetadataTests.swift b/Tests/ObjectWithValueMetadataTests.swift index 7fb12a4..da4778b 100644 --- a/Tests/ObjectWithValueMetadataTests.swift +++ b/Tests/ObjectWithValueMetadataTests.swift @@ -32,8 +32,8 @@ class ObjectWithValueMetadataTests: XCTestCase { var reader: Read! - var dispatchQueue: dispatch_queue_t! - var operationQueue: NSOperationQueue! + var dispatchQueue: DispatchQueue! + var operationQueue: OperationQueue! override func setUp() { super.setUp() @@ -53,8 +53,8 @@ class ObjectWithValueMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0) - operationQueue = NSOperationQueue() + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + operationQueue = OperationQueue() } override func tearDown() { @@ -104,7 +104,7 @@ class ObjectWithValueMetadataTests: XCTestCase { readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: YapItem) { + func checkTransactionDidWriteItem(_ result: YapItem) { XCTAssertEqual(result.value.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) @@ -112,7 +112,7 @@ class ObjectWithValueMetadataTests: XCTestCase { XCTAssertEqual(MetadataTypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].2), metadata) } - func checkTransactionDidWriteItems(result: [YapItem]) { + func checkTransactionDidWriteItems(_ result: [YapItem]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) @@ -120,7 +120,7 @@ class ObjectWithValueMetadataTests: XCTestCase { XCTAssertEqual(Set(result.map({$0.value})), Set(items)) } - func checkTransactionDidReadItem(result: YapItem?) -> Bool { + func checkTransactionDidReadItem(_ result: YapItem?) -> Bool { guard let result = result else { return false } @@ -131,7 +131,7 @@ class ObjectWithValueMetadataTests: XCTestCase { return true } - func checkTransactionDidReadItems(result: [YapItem]) -> Bool { + func checkTransactionDidReadItems(_ result: [YapItem]) -> Bool { if result.isEmpty { return false } @@ -303,24 +303,24 @@ class Functional_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest func test__connection__async_write_item() { var result: YapItem! - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") connection.asyncWriteWithMetadata(YapItem(item, metadata)) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItem(result) XCTAssertTrue(connection.didAsyncWrite) } func test__connection__async_write_items() { var result: [YapItem] = [] - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") connection.asyncWriteWithMetadata(items.yapItems(with: metadatas)) { received in result = received expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItems(result) XCTAssertTrue(connection.didAsyncWrite) } @@ -355,23 +355,23 @@ class Functional_Remove_ObjectWithValueMetadataTests: ObjectWithValueMetadataTes } func test__connection_async_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() connection.asyncRemove(item) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_async_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() connection.asyncRemove(items) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didAsyncWrite) } @@ -447,14 +447,14 @@ class Persistable_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest func test__reader__in_transaction_at_index_2() { configureForReadingSingle() reader = Read(readTransaction) - let atIndex: YapDB.Index -> YapItem? = reader.withMetadataInTransactionAtIndex(readTransaction) + let atIndex: (YapDB.Index) -> YapItem? = reader.withMetadataInTransactionAtIndex(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(atIndex(index))) } func test__reader__at_index_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataAtIndexInTransaction(index) + let inTransaction: (TestableReadTransaction) -> YapItem? = reader.withMetadataAtIndexInTransaction(index) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -478,14 +478,14 @@ class Persistable_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest func test__reader__in_transaction_by_key_2() { configureForReadingSingle() reader = Read(readTransaction) - let byKey: String -> YapItem? = reader.withMetadataInTransactionByKey(readTransaction) + let byKey: (String) -> YapItem? = reader.withMetadataInTransactionByKey(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(byKey(key))) } func test__reader__by_key_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataByKeyInTransaction(key) + let inTransaction: (TestableReadTransaction) -> YapItem? = reader.withMetadataByKeyInTransaction(key) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -667,20 +667,20 @@ class Persistable_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTes } func test__item_persistable__write_async_using_connection() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") var result: YapItem! = nil item.asyncWriteWithMetadata(connection, metadata: metadata) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItem(result) XCTAssertTrue(connection.didAsyncWrite) } func test__item_persistable__write_using_opertion() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") let operation = item.writeWithMetadataOperation(connection, metadata: metadata) operation.completionBlock = { @@ -688,7 +688,7 @@ class Persistable_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTes } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) @@ -706,20 +706,20 @@ class Persistable_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTes } func test__items_persistable__write_async_using_connection() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") var result: [YapItem] = [] items.asyncWriteWithMetadata(connection, metadata: metadatas) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItems(result) XCTAssertTrue(connection.didAsyncWrite) } func test__items_persistable__write_using_opertion() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") let operation = items.writeOperation(connection) operation.completionBlock = { @@ -727,7 +727,7 @@ class Persistable_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTes } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) @@ -751,25 +751,25 @@ class Persistable_Remove_ObjectWithValueMetadataTests: ObjectWithValueMetadataTe } func test__connection_async_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() item.asyncRemove(connection) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_operation_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() let operation = item.removeOperation(connection) operation.completionBlock = { expectation.fulfill() } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didWrite) } @@ -789,25 +789,25 @@ class Persistable_Remove_ObjectWithValueMetadataTests: ObjectWithValueMetadataTe } func test__connection_async_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() items.asyncRemove(connection) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_operation_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() let operation = items.removeOperation(connection) operation.completionBlock = { expectation.fulfill() } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didWrite) } diff --git a/Tests/ReadWriteTests.swift b/Tests/ReadWriteTests.swift index f526e8d..b672166 100644 --- a/Tests/ReadWriteTests.swift +++ b/Tests/ReadWriteTests.swift @@ -10,12 +10,12 @@ import YapDatabase class ReadWriteBaseTests: XCTestCase { var item: Employee! - var metadata: NSDate! + var metadata: Date! var index: YapDB.Index! var key: String! var items: [Employee]! - var metadatas: [NSDate?]! + var metadatas: [Date?]! var indexes: [YapDB.Index]! var keys: [String]! @@ -43,7 +43,7 @@ class ReadWriteBaseTests: XCTestCase { func createPersistables() { item = Employee(id: "beatle-1", name: "John") - metadata = NSDate() + metadata = Date() items = [ item, Employee(id: "beatle-2", name: "Paul"), @@ -52,13 +52,13 @@ class ReadWriteBaseTests: XCTestCase { ] metadatas = [ metadata, - NSDate(), - NSDate(), - NSDate() + Date(), + Date(), + Date() ] } - func writeItemsToDatabase(db: YapDatabase) { + func writeItemsToDatabase(_ db: YapDatabase) { db.makeNewConnection().writeWithMetadata(items.yapItems(with: metadatas)) } } diff --git a/Tests/Support.swift b/Tests/Support.swift index b256da5..40ed22b 100644 --- a/Tests/Support.swift +++ b/Tests/Support.swift @@ -12,7 +12,7 @@ import Foundation class TestableReadTransaction { var keys: [String] = [] - var didKeysInCollection: String? = .None + var didKeysInCollection: String? = .none var object: AnyObject? { get { return objects.first } @@ -53,7 +53,7 @@ class TestableReadTransaction { currentReadIndex += 1 return object } - return .None + return .none } func getNextMetadata() -> AnyObject? { @@ -62,23 +62,23 @@ class TestableReadTransaction { currentMetadataReadIndex += 1 return object } - return .None + return .none } } extension TestableReadTransaction: ReadTransactionType { - func keysInCollection(collection: String) -> [String] { + func keysInCollection(_ collection: String) -> [String] { didKeysInCollection = collection return keys } - func readAtIndex(index: YapDB.Index) -> AnyObject? { + func readAtIndex(_ index: YapDB.Index) -> AnyObject? { didReadAtIndexes.append(index) return getNextObject() } - func readMetadataAtIndex(index: YapDB.Index) -> AnyObject? { + func readMetadataAtIndex(_ index: YapDB.Index) -> AnyObject? { didReadMetadataAtIndexes.append(index) return getNextMetadata() } @@ -93,14 +93,14 @@ class TestableWriteTransaction: TestableReadTransaction { extension TestableWriteTransaction: WriteTransactionType { - func writeAtIndex(index: YapDB.Index, object: AnyObject, metadata: AnyObject?) { + func writeAtIndex(_ index: YapDB.Index, object: AnyObject, metadata: AnyObject?) { didWriteAtIndexes.append((index, object, metadata)) } func removeAtIndexes< - Indexes where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) { + Indexes>(_ indexes: Indexes) where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index { didRemoveAtIndexes = Array(indexes) } } @@ -118,34 +118,34 @@ class TestableConnection { extension TestableConnection: ConnectionType { - func read(block: TestableReadTransaction -> T) -> T { + func read(_ block: (TestableReadTransaction) -> T) -> T { didRead = true return block(readTransaction) } - func write(block: TestableWriteTransaction -> T) -> T { + func write(_ block: (TestableWriteTransaction) -> T) -> T { didWrite = true return block(writeTransaction) } - func asyncRead(block: TestableReadTransaction -> T, queue: dispatch_queue_t, completion: (T) -> Void) { + func asyncRead(_ block: @escaping (TestableReadTransaction) -> T, queue: DispatchQueue, completion: @escaping (T) -> Void) { didAsyncRead = true - dispatch_async(queue) { [transaction = self.readTransaction] in + queue.async { [transaction = self.readTransaction] in completion(block(transaction)) } } - func asyncWrite(block: TestableWriteTransaction -> T, queue: dispatch_queue_t, completion: (T -> Void)? = .None) { + func asyncWrite(_ block: @escaping (TestableWriteTransaction) -> T, queue: DispatchQueue, completion: ((T) -> Void)? = .none) { didAsyncWrite = true - dispatch_async(queue) { [transaction = self.writeTransaction] in + queue.async { [transaction = self.writeTransaction] in let result = block(transaction) completion?(result) } } - func writeBlockOperation(block: TestableWriteTransaction -> Void) -> NSOperation { + func writeBlockOperation(_ block: @escaping (TestableWriteTransaction) -> Void) -> Operation { didWriteBlockOperation = true - return NSBlockOperation { block(self.writeTransaction) } + return BlockOperation { block(self.writeTransaction) } } } diff --git a/Tests/ValueWithNoMetadataTests.swift b/Tests/ValueWithNoMetadataTests.swift index dc15538..032e2f0 100644 --- a/Tests/ValueWithNoMetadataTests.swift +++ b/Tests/ValueWithNoMetadataTests.swift @@ -31,8 +31,8 @@ class ValueWithNoMetadataTests: XCTestCase { var reader: Read! - var dispatchQueue: dispatch_queue_t! - var operationQueue: NSOperationQueue! + var dispatchQueue: DispatchQueue! + var operationQueue: OperationQueue! override func setUp() { super.setUp() @@ -52,8 +52,8 @@ class ValueWithNoMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0) - operationQueue = NSOperationQueue() + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + operationQueue = OperationQueue() } override func tearDown() { @@ -74,12 +74,12 @@ class ValueWithNoMetadataTests: XCTestCase { } func createPersistables() { - item = .QRCode("I have no idea what the string of a QR Code might look like") + item = .qrCode("I have no idea what the string of a QR Code might look like") items = [ item, - .UPCA(23, 42, 78, 93), - .QRCode("This is a different QR Code!"), - .UPCA(68, 59, 147, 291) + .upca(23, 42, 78, 93), + .qrCode("This is a different QR Code!"), + .upca(68, 59, 147, 291) ] } @@ -92,7 +92,7 @@ class ValueWithNoMetadataTests: XCTestCase { readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: TypeUnderTest) { + func checkTransactionDidWriteItem(_ result: TypeUnderTest) { XCTAssertEqual(result.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) @@ -100,7 +100,7 @@ class ValueWithNoMetadataTests: XCTestCase { XCTAssertNil(writeTransaction.didWriteAtIndexes[0].2) } - func checkTransactionDidWriteItems(result: [TypeUnderTest]) { + func checkTransactionDidWriteItems(_ result: [TypeUnderTest]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) @@ -108,7 +108,7 @@ class ValueWithNoMetadataTests: XCTestCase { XCTAssertEqual(Set(result), Set(items)) } - func checkTransactionDidReadItem(result: TypeUnderTest?) -> Bool { + func checkTransactionDidReadItem(_ result: TypeUnderTest?) -> Bool { guard let result = result else { return false } @@ -117,7 +117,7 @@ class ValueWithNoMetadataTests: XCTestCase { return true } - func checkTransactionDidReadItems(result: [TypeUnderTest]) -> Bool { + func checkTransactionDidReadItems(_ result: [TypeUnderTest]) -> Bool { if result.isEmpty { return false } @@ -289,24 +289,24 @@ class Functional_Write_ValueWithNoMetadataTests: ValueWithNoMetadataTests { func test__connection__async_write_item() { var result: TypeUnderTest! - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") connection.asyncWrite(item) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItem(result) XCTAssertTrue(connection.didAsyncWrite) } func test__connection__async_write_items() { var result: [TypeUnderTest] = [] - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") connection.asyncWrite(items) { received in result = received expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItems(result) XCTAssertTrue(connection.didAsyncWrite) } @@ -341,23 +341,23 @@ class Functional_Remove_ValueWithNoMetadataTests: ValueWithNoMetadataTests { } func test__connection_async_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() connection.asyncRemove(item) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_async_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() connection.asyncRemove(items) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didAsyncWrite) } @@ -653,20 +653,20 @@ class Persistable_Write_ValueWithNoMetadataTests: ValueWithNoMetadataTests { } func test__item_persistable__write_async_using_connection() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") var result: TypeUnderTest! = nil item.asyncWrite(connection) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItem(result) XCTAssertTrue(connection.didAsyncWrite) } func test__item_persistable__write_using_opertion() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") let operation = item.writeOperation(connection) operation.completionBlock = { @@ -674,7 +674,7 @@ class Persistable_Write_ValueWithNoMetadataTests: ValueWithNoMetadataTests { } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(TypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].1)!, item) @@ -692,20 +692,20 @@ class Persistable_Write_ValueWithNoMetadataTests: ValueWithNoMetadataTests { } func test__items_persistable__write_async_using_connection() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") var result: [TypeUnderTest] = [] items.asyncWrite(connection) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItems(result) XCTAssertTrue(connection.didAsyncWrite) } func test__items_persistable__write_using_opertion() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") let operation = items.writeOperation(connection) operation.completionBlock = { @@ -713,7 +713,7 @@ class Persistable_Write_ValueWithNoMetadataTests: ValueWithNoMetadataTests { } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) @@ -737,25 +737,25 @@ class Persistable_Remove_ValueWithNoMetadataTests: ValueWithNoMetadataTests { } func test__connection_async_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() item.asyncRemove(connection) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_operation_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() let operation = item.removeOperation(connection) operation.completionBlock = { expectation.fulfill() } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didWrite) } @@ -775,25 +775,25 @@ class Persistable_Remove_ValueWithNoMetadataTests: ValueWithNoMetadataTests { } func test__connection_async_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() items.asyncRemove(connection) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_operation_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() let operation = items.removeOperation(connection) operation.completionBlock = { expectation.fulfill() } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didWrite) } diff --git a/Tests/ValueWithObjectMetadataTests.swift b/Tests/ValueWithObjectMetadataTests.swift index b954985..1f7fb37 100644 --- a/Tests/ValueWithObjectMetadataTests.swift +++ b/Tests/ValueWithObjectMetadataTests.swift @@ -32,8 +32,8 @@ class ValueWithObjectMetadataTests: XCTestCase { var reader: Read! - var dispatchQueue: dispatch_queue_t! - var operationQueue: NSOperationQueue! + var dispatchQueue: DispatchQueue! + var operationQueue: OperationQueue! override func setUp() { super.setUp() @@ -53,8 +53,8 @@ class ValueWithObjectMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0) - operationQueue = NSOperationQueue() + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + operationQueue = OperationQueue() } override func tearDown() { @@ -101,10 +101,10 @@ class ValueWithObjectMetadataTests: XCTestCase { ] metadatas = [ - NSNumber(integer: 12), - NSNumber(integer: 13), - NSNumber(integer: 14), - NSNumber(integer: 15) + NSNumber(value: 12 as Int), + NSNumber(value: 13 as Int), + NSNumber(value: 14 as Int), + NSNumber(value: 15 as Int) ] items = products.map { TypeUnderTest(product: $0) } item = items[0] @@ -122,7 +122,7 @@ class ValueWithObjectMetadataTests: XCTestCase { readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: YapItem) { + func checkTransactionDidWriteItem(_ result: YapItem) { XCTAssertEqual(result.value.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) @@ -130,7 +130,7 @@ class ValueWithObjectMetadataTests: XCTestCase { XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSNumber, metadata) } - func checkTransactionDidWriteItems(result: [YapItem]) { + func checkTransactionDidWriteItems(_ result: [YapItem]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) @@ -138,7 +138,7 @@ class ValueWithObjectMetadataTests: XCTestCase { XCTAssertEqual(Set(result.map({$0.value})), Set(items)) } - func checkTransactionDidReadItem(result: YapItem?) -> Bool { + func checkTransactionDidReadItem(_ result: YapItem?) -> Bool { XCTAssertEqual(readTransaction.didReadAtIndex, index) guard let result = result else { return false @@ -149,7 +149,7 @@ class ValueWithObjectMetadataTests: XCTestCase { return true } - func checkTransactionDidReadItems(result: [YapItem]) -> Bool { + func checkTransactionDidReadItems(_ result: [YapItem]) -> Bool { if result.isEmpty { return false } @@ -158,7 +158,7 @@ class ValueWithObjectMetadataTests: XCTestCase { return true } - func checkTransactionDidReadMetadataItem(result: MetadataTypeUnderTest?) -> Bool { + func checkTransactionDidReadMetadataItem(_ result: MetadataTypeUnderTest?) -> Bool { XCTAssertNil(readTransaction.didReadAtIndex) guard let result = result else { return false @@ -168,7 +168,7 @@ class ValueWithObjectMetadataTests: XCTestCase { return true } - func checkTransactionDidReadMetadataItems(result: [MetadataTypeUnderTest]) -> Bool { + func checkTransactionDidReadMetadataItems(_ result: [MetadataTypeUnderTest]) -> Bool { XCTAssertTrue(readTransaction.didReadAtIndexes.isEmpty) if result.isEmpty { return false @@ -385,24 +385,24 @@ class Functional_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest func test__connection__async_write_item() { var result: YapItem! - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") connection.asyncWriteWithMetadata(YapItem(item, metadata)) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItem(result) XCTAssertTrue(connection.didAsyncWrite) } func test__connection__async_write_items() { var result: [YapItem] = [] - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") connection.asyncWriteWithMetadata(items.yapItems(with: metadatas)) { received in result = received expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItems(result) XCTAssertTrue(connection.didAsyncWrite) } @@ -437,23 +437,23 @@ class Functional_Remove_ValueWithObjectMetadataTests: ValueWithObjectMetadataTes } func test__connection_async_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() connection.asyncRemove(item) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_async_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() connection.asyncRemove(items) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didAsyncWrite) } @@ -529,14 +529,14 @@ class Persistable_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest func test__reader__in_transaction_at_index_2() { configureForReadingSingle() reader = Read(readTransaction) - let atIndex: YapDB.Index -> YapItem? = reader.withMetadataInTransactionAtIndex(readTransaction) + let atIndex: (YapDB.Index) -> YapItem? = reader.withMetadataInTransactionAtIndex(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(atIndex(index))) } func test__reader__at_index_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataAtIndexInTransaction(index) + let inTransaction: (TestableReadTransaction) -> YapItem? = reader.withMetadataAtIndexInTransaction(index) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -560,14 +560,14 @@ class Persistable_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest func test__reader__in_transaction_by_key_2() { configureForReadingSingle() reader = Read(readTransaction) - let byKey: String -> YapItem? = reader.withMetadataInTransactionByKey(readTransaction) + let byKey: (String) -> YapItem? = reader.withMetadataInTransactionByKey(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(byKey(key))) } func test__reader__by_key_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataByKeyInTransaction(key) + let inTransaction: (TestableReadTransaction) -> YapItem? = reader.withMetadataByKeyInTransaction(key) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -800,20 +800,20 @@ class Persistable_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTes } func test__item_persistable__write_async_using_connection() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") var result: YapItem! = nil item.asyncWriteWithMetadata(connection, metadata: metadata) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItem(result) XCTAssertTrue(connection.didAsyncWrite) } func test__item_persistable__write_using_opertion() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") let operation = item.writeWithMetadataOperation(connection, metadata: metadata) operation.completionBlock = { @@ -821,7 +821,7 @@ class Persistable_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTes } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(TypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].1)!, item) @@ -839,20 +839,20 @@ class Persistable_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTes } func test__items_persistable__write_async_using_connection() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") var result: [YapItem] = [] items.asyncWriteWithMetadata(connection, metadata: metadatas) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItems(result) XCTAssertTrue(connection.didAsyncWrite) } func test__items_persistable__write_using_opertion() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") let operation = items.writeWithMetadataOperation(connection, metadata: metadatas) operation.completionBlock = { @@ -860,7 +860,7 @@ class Persistable_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTes } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) @@ -884,25 +884,25 @@ class Persistable_Remove_ValueWithObjectMetadataTests: ValueWithObjectMetadataTe } func test__connection_async_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() item.asyncRemove(connection) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_operation_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() let operation = item.removeOperation(connection) operation.completionBlock = { expectation.fulfill() } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didWrite) } @@ -922,25 +922,25 @@ class Persistable_Remove_ValueWithObjectMetadataTests: ValueWithObjectMetadataTe } func test__connection_async_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() items.asyncRemove(connection) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_operation_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() let operation = items.removeOperation(connection) operation.completionBlock = { expectation.fulfill() } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didWrite) } diff --git a/Tests/ValueWithValueMetadataTests.swift b/Tests/ValueWithValueMetadataTests.swift index 4b1b257..7569cff 100644 --- a/Tests/ValueWithValueMetadataTests.swift +++ b/Tests/ValueWithValueMetadataTests.swift @@ -32,8 +32,8 @@ class ValueWithValueMetadataTests: XCTestCase { var reader: Read! - var dispatchQueue: dispatch_queue_t! - var operationQueue: NSOperationQueue! + var dispatchQueue: DispatchQueue! + var operationQueue: OperationQueue! override func setUp() { super.setUp() @@ -53,8 +53,8 @@ class ValueWithValueMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0) - operationQueue = NSOperationQueue() + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + operationQueue = OperationQueue() } override func tearDown() { @@ -120,7 +120,7 @@ class ValueWithValueMetadataTests: XCTestCase { readTransaction.keys = keys } - func checkTransactionDidWriteItem(result: YapItem) { + func checkTransactionDidWriteItem(_ result: YapItem) { XCTAssertEqual(result.value.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) @@ -128,7 +128,7 @@ class ValueWithValueMetadataTests: XCTestCase { XCTAssertEqual(MetadataTypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].2), metadata) } - func checkTransactionDidWriteItems(result: [YapItem]) { + func checkTransactionDidWriteItems(_ result: [YapItem]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) @@ -136,7 +136,7 @@ class ValueWithValueMetadataTests: XCTestCase { XCTAssertEqual(Set(result.map({$0.value})), Set(items)) } - func checkTransactionDidReadItem(result: YapItem?) -> Bool { + func checkTransactionDidReadItem(_ result: YapItem?) -> Bool { XCTAssertEqual(readTransaction.didReadAtIndex, index) guard let result = result else { return false @@ -147,7 +147,7 @@ class ValueWithValueMetadataTests: XCTestCase { return true } - func checkTransactionDidReadItems(result: [YapItem]) -> Bool { + func checkTransactionDidReadItems(_ result: [YapItem]) -> Bool { if result.isEmpty { return false } @@ -156,7 +156,7 @@ class ValueWithValueMetadataTests: XCTestCase { return true } - func checkTransactionDidReadMetadataItem(result: MetadataTypeUnderTest?) -> Bool { + func checkTransactionDidReadMetadataItem(_ result: MetadataTypeUnderTest?) -> Bool { XCTAssertNil(readTransaction.didReadAtIndex) guard let result = result else { return false @@ -166,7 +166,7 @@ class ValueWithValueMetadataTests: XCTestCase { return true } - func checkTransactionDidReadMetadataItems(result: [MetadataTypeUnderTest]) -> Bool { + func checkTransactionDidReadMetadataItems(_ result: [MetadataTypeUnderTest]) -> Bool { XCTAssertTrue(readTransaction.didReadAtIndexes.isEmpty) if result.isEmpty { return false @@ -382,24 +382,24 @@ class Functional_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests func test__connection__async_write_item() { var result: YapItem! - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") connection.asyncWriteWithMetadata(YapItem(item, metadata)) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItem(result) XCTAssertTrue(connection.didAsyncWrite) } func test__connection__async_write_items() { var result: [YapItem] = [] - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") connection.asyncWriteWithMetadata(items.yapItems(with: metadatas)) { received in result = received expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItems(result) XCTAssertTrue(connection.didAsyncWrite) } @@ -434,23 +434,23 @@ class Functional_Remove_ValueWithValueMetadataTests: ValueWithValueMetadataTests } func test__connection_async_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() connection.asyncRemove(item) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_async_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() connection.asyncRemove(items) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didAsyncWrite) } @@ -526,14 +526,14 @@ class Persistable_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests func test__reader__in_transaction_at_index_2() { configureForReadingSingle() reader = Read(readTransaction) - let atIndex: YapDB.Index -> YapItem? = reader.withMetadataInTransactionAtIndex(readTransaction) + let atIndex: (YapDB.Index) -> YapItem? = reader.withMetadataInTransactionAtIndex(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(atIndex(index))) } func test__reader__at_index_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataAtIndexInTransaction(index) + let inTransaction: (TestableReadTransaction) -> YapItem? = reader.withMetadataAtIndexInTransaction(index) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -557,14 +557,14 @@ class Persistable_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests func test__reader__in_transaction_by_key_2() { configureForReadingSingle() reader = Read(readTransaction) - let byKey: String -> YapItem? = reader.withMetadataInTransactionByKey(readTransaction) + let byKey: (String) -> YapItem? = reader.withMetadataInTransactionByKey(readTransaction) XCTAssertTrue(checkTransactionDidReadItem(byKey(key))) } func test__reader__by_key_in_transaction() { configureForReadingSingle() reader = Read(readTransaction) - let inTransaction: TestableReadTransaction -> YapItem? = reader.withMetadataByKeyInTransaction(key) + let inTransaction: (TestableReadTransaction) -> YapItem? = reader.withMetadataByKeyInTransaction(key) XCTAssertTrue(checkTransactionDidReadItem(inTransaction(readTransaction))) } @@ -797,20 +797,20 @@ class Persistable_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests } func test__item_persistable__write_async_using_connection() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") var result: YapItem! = nil item.asyncWriteWithMetadata(connection, metadata: metadata) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItem(result) XCTAssertTrue(connection.didAsyncWrite) } func test__item_persistable__write_using_opertion() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") let operation = item.writeWithMetadataOperation(connection, metadata: metadata) operation.completionBlock = { @@ -818,7 +818,7 @@ class Persistable_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(TypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].1)!, item) @@ -836,20 +836,20 @@ class Persistable_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests } func test__items_persistable__write_async_using_connection() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") var result: [YapItem] = [] items.asyncWriteWithMetadata(connection, metadata: metadatas) { tmp in result = tmp expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidWriteItems(result) XCTAssertTrue(connection.didAsyncWrite) } func test__items_persistable__write_using_opertion() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") let operation = items.writeWithMetadataOperation(connection, metadata: metadatas) operation.completionBlock = { @@ -857,7 +857,7 @@ class Persistable_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) @@ -881,25 +881,25 @@ class Persistable_Remove_ValueWithValueMetadataTests: ValueWithValueMetadataTest } func test__connection_async_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() item.asyncRemove(connection) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_operation_remove_item() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingSingle() let operation = item.removeOperation(connection) operation.completionBlock = { expectation.fulfill() } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItem() XCTAssertTrue(connection.didWrite) } @@ -919,25 +919,25 @@ class Persistable_Remove_ValueWithValueMetadataTests: ValueWithValueMetadataTest } func test__connection_async_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() items.asyncRemove(connection) { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didAsyncWrite) } func test__connection_operation_remove_items() { - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") configureForReadingMultiple() let operation = items.removeOperation(connection) operation.completionBlock = { expectation.fulfill() } operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) checkTransactionDidRemoveItems() XCTAssertTrue(connection.didWrite) } diff --git a/Tests/YapDatabaseExtensionsTests.swift b/Tests/YapDatabaseExtensionsTests.swift index b244ca2..2521d19 100644 --- a/Tests/YapDatabaseExtensionsTests.swift +++ b/Tests/YapDatabaseExtensionsTests.swift @@ -136,23 +136,23 @@ class YapDatabaseReadWriteTransactionTests: ReadWriteBaseTests { class YapDatabaseConnectionTests: ReadWriteBaseTests { - var dispatchQueue: dispatch_queue_t! - var operationQueue: NSOperationQueue! + var dispatchQueue: DispatchQueue! + var operationQueue: OperationQueue! override func setUp() { super.setUp() - dispatchQueue = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0) - operationQueue = NSOperationQueue() + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + operationQueue = OperationQueue() } func test__async_read() { let db = YapDB.testDatabase() - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") db.makeNewConnection().write(item) XCTAssertNotNil(Employee.read(db).atIndex(index)) - var received: Employee? = .None + var received: Employee? = .none db.newConnection().asyncRead({ transaction -> Employee? in return transaction.readAtIndex(self.index) as? Employee }, queue: dispatchQueue) { (result: Employee?) in @@ -160,16 +160,16 @@ class YapDatabaseConnectionTests: ReadWriteBaseTests { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertNotNil(received) } func test__async_write() { let db = YapDB.testDatabase() - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") - var written: Employee? = .None + var written: Employee? = .none db.makeNewConnection().asyncWrite({ transaction -> Employee? in transaction.writeAtIndex(self.index, object: self.item, metadata: self.metadata) return self.item @@ -178,7 +178,7 @@ class YapDatabaseConnectionTests: ReadWriteBaseTests { expectation.fulfill() } - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertNotNil(written) XCTAssertNotNil(Employee.read(db).atIndex(index)) @@ -186,7 +186,7 @@ class YapDatabaseConnectionTests: ReadWriteBaseTests { func test__writeBlockOperation() { let db = YapDB.testDatabase() - let expectation = expectationWithDescription("Test: \(#function)") + let expectation = self.expectation(description: "Test: \(#function)") var didExecuteWithTransaction = false let operation = db.makeNewConnection().writeBlockOperation { transaction in @@ -196,7 +196,7 @@ class YapDatabaseConnectionTests: ReadWriteBaseTests { operationQueue.addOperation(operation) - waitForExpectationsWithTimeout(3.0, handler: nil) + waitForExpectations(timeout: 3.0, handler: nil) XCTAssertTrue(operation.finished) XCTAssertTrue(didExecuteWithTransaction) } diff --git a/YapDatabaseExtensions.xcodeproj/project.pbxproj b/YapDatabaseExtensions.xcodeproj/project.pbxproj index 00e948c..5c997d2 100644 --- a/YapDatabaseExtensions.xcodeproj/project.pbxproj +++ b/YapDatabaseExtensions.xcodeproj/project.pbxproj @@ -270,11 +270,11 @@ TargetAttributes = { 656BAE6F1D9A4CCC008279EE = { CreatedOnToolsVersion = 7.3.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 0820; }; 656BAE791D9A4CCC008279EE = { CreatedOnToolsVersion = 7.3.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 0820; }; }; }; @@ -497,7 +497,7 @@ ONLY_ACTIVE_ARCH = YES; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -543,7 +543,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; SKIP_INSTALL = YES; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -593,7 +593,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -633,7 +633,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Release; }; From a95b199024ae15b7d0941b8e8dfbb6d3b78e182d Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 00:05:32 -0800 Subject: [PATCH 19/54] run the Swift 3 converter again --- Sources/Curried_ObjectWithNoMetadata.swift | 26 ++++---- Sources/Functional_Remove.swift | 4 +- Sources/Functional_ValueWithNoMetadata.swift | 2 +- .../Persistable_ObjectWithNoMetadata.swift | 64 +++++++++---------- Sources/Persistable_Remove.swift | 4 +- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/Sources/Curried_ObjectWithNoMetadata.swift b/Sources/Curried_ObjectWithNoMetadata.swift index 4ec7b60..fdd3454 100644 --- a/Sources/Curried_ObjectWithNoMetadata.swift +++ b/Sources/Curried_ObjectWithNoMetadata.swift @@ -22,8 +22,8 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readAtIndex< - ReadTransaction where - ReadTransaction: ReadTransactionType>(index: YapDB.Index) -> ReadTransaction -> Self? { + ReadTransaction>(_ index: YapDB.Index) -> (ReadTransaction) -> Self? where + ReadTransaction: ReadTransactionType { return { $0.readAtIndex(index) } } @@ -35,10 +35,10 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readAtIndexes< - Indexes, ReadTransaction where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index, - ReadTransaction: ReadTransactionType>(indexes: Indexes) -> ReadTransaction -> [Self] { + Indexes, ReadTransaction>(_ indexes: Indexes) -> (ReadTransaction) -> [Self] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index, + ReadTransaction: ReadTransactionType { return { $0.readAtIndexes(indexes) } } @@ -50,8 +50,8 @@ extension Persistable where - returns: a (ReadTransaction) -> Self? closure. */ public static func readByKey< - ReadTransaction where - ReadTransaction: ReadTransactionType>(key: String) -> ReadTransaction -> Self? { + ReadTransaction>(_ key: String) -> (ReadTransaction) -> Self? where + ReadTransaction: ReadTransactionType { return { $0.readByKey(key) } } @@ -63,10 +63,10 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readByKeys< - Keys, ReadTransaction where - Keys: SequenceType, - Keys.Generator.Element == String, - ReadTransaction: ReadTransactionType>(keys: Keys) -> ReadTransaction -> [Self] { + Keys, ReadTransaction>(_ keys: Keys) -> (ReadTransaction) -> [Self] where + Keys: Sequence, + Keys.Iterator.Element == String, + ReadTransaction: ReadTransactionType { return { $0.readAtIndexes(Self.indexesWithKeys(keys)) } } @@ -77,7 +77,7 @@ extension Persistable where - warning: Be aware that this will capure `self`. - returns: a (WriteTransaction) -> Self closure */ - public func write() -> WriteTransaction -> Self { + public func write() -> (WriteTransaction) -> Self { return { $0.write(self) } } } diff --git a/Sources/Functional_Remove.swift b/Sources/Functional_Remove.swift index 306cdac..443d8cb 100644 --- a/Sources/Functional_Remove.swift +++ b/Sources/Functional_Remove.swift @@ -66,7 +66,7 @@ extension ConnectionType { - parameter item: a `Persistable` item */ public func asyncRemove(_ item: Item, queue: DispatchQueue = DispatchQueue.main, completion: @escaping ()->()? = .none) { - asyncWrite({ $0.remove(item) }, queue: queue, completion: { _ in completion?() }) + asyncWrite({ $0.remove(item) }, queue: queue, completion: { _ in completion() }) } /** @@ -80,6 +80,6 @@ extension ConnectionType { Items: Sequence, Items.Iterator.Element == Item, Item: Persistable { - asyncWrite({ $0.remove(items) }, queue: queue, completion: { _ in completion?() }) + asyncWrite({ $0.remove(items) }, queue: queue, completion: { _ in completion() }) } } diff --git a/Sources/Functional_ValueWithNoMetadata.swift b/Sources/Functional_ValueWithNoMetadata.swift index fc813d2..813c0fb 100644 --- a/Sources/Functional_ValueWithNoMetadata.swift +++ b/Sources/Functional_ValueWithNoMetadata.swift @@ -189,7 +189,7 @@ extension WriteTransactionType { Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.Value == Value { - writeAtIndex(item.index, object: item.encoded, metadata: .None) + writeAtIndex(item.index, object: item.encoded, metadata: .none) return item } diff --git a/Sources/Persistable_ObjectWithNoMetadata.swift b/Sources/Persistable_ObjectWithNoMetadata.swift index e390fd0..261da6c 100644 --- a/Sources/Persistable_ObjectWithNoMetadata.swift +++ b/Sources/Persistable_ObjectWithNoMetadata.swift @@ -22,7 +22,7 @@ extension Persistable where - parameter transaction: a YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(transaction: WriteTransaction) -> Self { + public func write(_ transaction: WriteTransaction) -> Self { return transaction.write(self) } @@ -32,7 +32,7 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: the receiver. */ - public func write(connection: Connection) -> Self { + public func write(_ connection: Connection) -> Self { return connection.write(self) } @@ -42,7 +42,7 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (Self -> Void)? = .None) { + public func asyncWrite(_ connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self) -> Void)? = .none) { return connection.asyncWrite(self, queue: queue, completion: completion) } @@ -52,14 +52,14 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.write(self) } + public func writeOperation(_ connection: Connection) -> Operation { + return BlockOperation { connection.write(self) } } } -extension SequenceType where - Generator.Element: Persistable, - Generator.Element: NSCoding { +extension Sequence where + Iterator.Element: Persistable, + Iterator.Element: NSCoding { /** Write the items using an existing transaction. @@ -67,7 +67,7 @@ extension SequenceType where - parameter transaction: a WriteTransactionType e.g. YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(transaction: WriteTransaction) -> [Generator.Element] { + public func write(_ transaction: WriteTransaction) -> [Generator.Element] { return transaction.write(self) } @@ -77,7 +77,7 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: the receiver. */ - public func write(connection: Connection) -> [Generator.Element] { + public func write(_ connection: Connection) -> [Generator.Element] { return connection.write(self) } @@ -87,7 +87,7 @@ extension SequenceType where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ([Generator.Element] -> Void)? = .None) { + public func asyncWrite(_ connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (([Generator.Element]) -> Void)? = .None) { return connection.asyncWrite(self, queue: queue, completion: completion) } @@ -97,8 +97,8 @@ extension SequenceType where - parameter connection: a YapDatabaseConnection - returns: an `NSOperation` */ - public func writeOperation(connection: Connection) -> NSOperation { - return NSBlockOperation { connection.write(self) } + public func writeOperation(_ connection: Connection) -> Operation { + return BlockOperation { connection.write(self) } } } @@ -108,39 +108,39 @@ extension Readable where ItemType: NSCoding, ItemType: Persistable { - func inTransaction(transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> ItemType? { + func inTransaction(_ transaction: Database.Connection.ReadTransaction, atIndex index: YapDB.Index) -> ItemType? { return transaction.readAtIndex(index) } - func inTransactionAtIndex(transaction: Database.Connection.ReadTransaction) -> YapDB.Index -> ItemType? { + func inTransactionAtIndex(_ transaction: Database.Connection.ReadTransaction) -> (YapDB.Index) -> ItemType? { return { self.inTransaction(transaction, atIndex: $0) } } - func atIndexInTransaction(index: YapDB.Index) -> Database.Connection.ReadTransaction -> ItemType? { + func atIndexInTransaction(_ index: YapDB.Index) -> (Database.Connection.ReadTransaction) -> ItemType? { return { self.inTransaction($0, atIndex: index) } } func atIndexesInTransaction< - Indexes where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> Database.Connection.ReadTransaction -> [ItemType] { + Indexes>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [ItemType] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index { let atIndex = inTransactionAtIndex return { indexes.flatMap(atIndex($0)) } } - func inTransaction(transaction: Database.Connection.ReadTransaction, byKey key: String) -> ItemType? { + func inTransaction(_ transaction: Database.Connection.ReadTransaction, byKey key: String) -> ItemType? { return inTransaction(transaction, atIndex: ItemType.indexWithKey(key)) } - func inTransactionByKey(transaction: Database.Connection.ReadTransaction) -> String -> ItemType? { + func inTransactionByKey(_ transaction: Database.Connection.ReadTransaction) -> (String) -> ItemType? { return { self.inTransaction(transaction, byKey: $0) } } - func byKeyInTransaction(key: String) -> Database.Connection.ReadTransaction -> ItemType? { + func byKeyInTransaction(_ key: String) -> (Database.Connection.ReadTransaction) -> ItemType? { return { self.inTransaction($0, byKey: key) } } - func byKeysInTransaction(keys: [String]? = .None) -> Database.Connection.ReadTransaction -> [ItemType] { + func byKeysInTransaction(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [ItemType] { let byKey = inTransactionByKey return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) @@ -154,7 +154,7 @@ extension Readable where - parameter index: a YapDB.Index - returns: an optional `ItemType` */ - public func atIndex(index: YapDB.Index) -> ItemType? { + public func atIndex(_ index: YapDB.Index) -> ItemType? { return sync(atIndexInTransaction(index)) } @@ -165,9 +165,9 @@ extension Readable where - returns: an array of `ItemType` */ public func atIndexes< - Indexes where - Indexes: SequenceType, - Indexes.Generator.Element == YapDB.Index>(indexes: Indexes) -> [ItemType] { + Indexes>(_ indexes: Indexes) -> [ItemType] where + Indexes: Sequence, + Indexes.Iterator.Element == YapDB.Index { return sync(atIndexesInTransaction(indexes)) } @@ -177,7 +177,7 @@ extension Readable where - parameter key: a String - returns: an optional `ItemType` */ - public func byKey(key: String) -> ItemType? { + public func byKey(_ key: String) -> ItemType? { return sync(byKeyInTransaction(key)) } @@ -188,9 +188,9 @@ extension Readable where - returns: an array of `ItemType` */ public func byKeys< - Keys where - Keys: SequenceType, - Keys.Generator.Element == String>(keys: Keys) -> [ItemType] { + Keys>(_ keys: Keys) -> [ItemType] where + Keys: Sequence, + Keys.Iterator.Element == String { return sync(byKeysInTransaction(Array(keys))) } @@ -209,7 +209,7 @@ extension Readable where - parameter keys: a SequenceType of String values - returns: a tuple of type `([ItemType], [String])` */ - public func filterExisting(keys: [String]) -> (existing: [ItemType], missing: [String]) { + public func filterExisting(_ keys: [String]) -> (existing: [ItemType], missing: [String]) { let existingInTransaction = byKeysInTransaction(keys) return sync { transaction -> ([ItemType], [String]) in let existing = existingInTransaction(transaction) diff --git a/Sources/Persistable_Remove.swift b/Sources/Persistable_Remove.swift index c003161..86c17c9 100644 --- a/Sources/Persistable_Remove.swift +++ b/Sources/Persistable_Remove.swift @@ -30,7 +30,7 @@ extension Persistable { - parameter connection: a `ConnectionType` connection */ - public func asyncRemove(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: ()->()? = .none) { + public func asyncRemove(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: @escaping ()->()? = .none) { connection.asyncRemove(self, queue: queue, completion: completion) } @@ -71,7 +71,7 @@ Iterator.Element: Persistable { - parameter connection: a `ConnectionType` connection */ - public func asyncRemove(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: ()->()? = .none) { + public func asyncRemove(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: @escaping ()->()? = .none) { connection.asyncRemove(self, queue: queue, completion: completion) } From 937f2f502b3cae1357ebad29df7548a249befde9 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 00:26:03 -0800 Subject: [PATCH 20/54] manual changes to get things building --- Sources/Functional_Remove.swift | 8 +++---- .../Persistable_ObjectWithNoMetadata.swift | 8 +++---- Sources/Persistable_Remove.swift | 4 ++-- Sources/Persistable_ValueWithNoMetadata.swift | 8 +++---- .../Persistable_ValueWithObjectMetadata.swift | 10 ++++----- .../Persistable_ValueWithValueMetadata.swift | 10 ++++----- Sources/Read.swift | 2 +- Sources/YapDB.swift | 2 +- Sources/YapDatabaseExtensions.swift | 22 ++++++++----------- Tests/Models.swift | 12 +++++----- Tests/ObjectWithNoMetadataTests.swift | 2 +- Tests/ObjectWithObjectMetadataTests.swift | 2 +- Tests/ObjectWithValueMetadataTests.swift | 2 +- Tests/ValueWithNoMetadataTests.swift | 2 +- Tests/ValueWithObjectMetadataTests.swift | 2 +- Tests/ValueWithValueMetadataTests.swift | 2 +- Tests/YapDatabaseExtensionsTests.swift | 2 +- 17 files changed, 48 insertions(+), 52 deletions(-) diff --git a/Sources/Functional_Remove.swift b/Sources/Functional_Remove.swift index 443d8cb..7074c6e 100644 --- a/Sources/Functional_Remove.swift +++ b/Sources/Functional_Remove.swift @@ -65,8 +65,8 @@ extension ConnectionType { - parameter item: a `Persistable` item */ - public func asyncRemove(_ item: Item, queue: DispatchQueue = DispatchQueue.main, completion: @escaping ()->()? = .none) { - asyncWrite({ $0.remove(item) }, queue: queue, completion: { _ in completion() }) + public func asyncRemove(_ item: Item, queue: DispatchQueue = DispatchQueue.main, completion: (()->())? = .none) { + asyncWrite({ $0.remove(item) }, queue: queue, completion: { _ in completion?() }) } /** @@ -76,10 +76,10 @@ extension ConnectionType { - parameter items: a sequence of `Persistable` items */ public func asyncRemove< - Items, Item>(_ items: Items, queue: DispatchQueue = DispatchQueue.main, completion: @escaping ()->()? = .none) where + Items, Item>(_ items: Items, queue: DispatchQueue = DispatchQueue.main, completion: (()->())? = .none) where Items: Sequence, Items.Iterator.Element == Item, Item: Persistable { - asyncWrite({ $0.remove(items) }, queue: queue, completion: { _ in completion() }) + asyncWrite({ $0.remove(items) }, queue: queue, completion: { _ in completion?() }) } } diff --git a/Sources/Persistable_ObjectWithNoMetadata.swift b/Sources/Persistable_ObjectWithNoMetadata.swift index 261da6c..fc810c7 100644 --- a/Sources/Persistable_ObjectWithNoMetadata.swift +++ b/Sources/Persistable_ObjectWithNoMetadata.swift @@ -42,7 +42,7 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(_ connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self) -> Void)? = .none) { + public func asyncWrite(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: ((Self) -> Void)? = .none) { return connection.asyncWrite(self, queue: queue, completion: completion) } @@ -67,7 +67,7 @@ extension Sequence where - parameter transaction: a WriteTransactionType e.g. YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(_ transaction: WriteTransaction) -> [Generator.Element] { + public func write(_ transaction: WriteTransaction) -> [Iterator.Element] { return transaction.write(self) } @@ -77,7 +77,7 @@ extension Sequence where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: the receiver. */ - public func write(_ connection: Connection) -> [Generator.Element] { + public func write(_ connection: Connection) -> [Iterator.Element] { return connection.write(self) } @@ -87,7 +87,7 @@ extension Sequence where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(_ connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (([Generator.Element]) -> Void)? = .None) { + public func asyncWrite(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: (([Iterator.Element]) -> Void)? = .none) { return connection.asyncWrite(self, queue: queue, completion: completion) } diff --git a/Sources/Persistable_Remove.swift b/Sources/Persistable_Remove.swift index 86c17c9..62b1ba9 100644 --- a/Sources/Persistable_Remove.swift +++ b/Sources/Persistable_Remove.swift @@ -30,7 +30,7 @@ extension Persistable { - parameter connection: a `ConnectionType` connection */ - public func asyncRemove(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: @escaping ()->()? = .none) { + public func asyncRemove(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: (()->())? = .none) { connection.asyncRemove(self, queue: queue, completion: completion) } @@ -71,7 +71,7 @@ Iterator.Element: Persistable { - parameter connection: a `ConnectionType` connection */ - public func asyncRemove(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: @escaping ()->()? = .none) { + public func asyncRemove(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: (()->())? = .none) { connection.asyncRemove(self, queue: queue, completion: completion) } diff --git a/Sources/Persistable_ValueWithNoMetadata.swift b/Sources/Persistable_ValueWithNoMetadata.swift index dec1657..7613851 100644 --- a/Sources/Persistable_ValueWithNoMetadata.swift +++ b/Sources/Persistable_ValueWithNoMetadata.swift @@ -44,7 +44,7 @@ extension Persistable where - parameter connection: a YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(_ connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((Self) -> Void)? = .none) { + public func asyncWrite(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: ((Self) -> Void)? = .none) { return connection.asyncWrite(self, queue: queue, completion: completion) } @@ -71,7 +71,7 @@ extension Sequence where - parameter transaction: a WriteTransactionType e.g. YapDatabaseReadWriteTransaction - returns: the receiver. */ - public func write(_ transaction: WriteTransaction) -> [Generator.Element] { + public func write(_ transaction: WriteTransaction) -> [Iterator.Element] { return transaction.write(self) } @@ -81,7 +81,7 @@ extension Sequence where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: the receiver. */ - public func write(_ connection: Connection) -> [Generator.Element] { + public func write(_ connection: Connection) -> [Iterator.Element] { return connection.write(self) } @@ -91,7 +91,7 @@ extension Sequence where - parameter connection: a ConnectionType e.g. YapDatabaseConnection - returns: a closure which receives as an argument the receiver of this function. */ - public func asyncWrite(_ connection: Connection, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (([Generator.Element]) -> Void)? = .None) { + public func asyncWrite(_ connection: Connection, queue: DispatchQueue = DispatchQueue.main, completion: (([Iterator.Element]) -> Void)? = .none) { return connection.asyncWrite(self, queue: queue, completion: completion) } diff --git a/Sources/Persistable_ValueWithObjectMetadata.swift b/Sources/Persistable_ValueWithObjectMetadata.swift index 1bd9804..7995200 100644 --- a/Sources/Persistable_ValueWithObjectMetadata.swift +++ b/Sources/Persistable_ValueWithObjectMetadata.swift @@ -51,7 +51,7 @@ extension Persistable where - returns: a closure which receives as an argument the receiver of this function. */ public func asyncWriteWithMetadata< - Connection, Metadata>(_ connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((YapItem) -> Void)? = .none) where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?, queue: DispatchQueue = DispatchQueue.main, completion: ((YapItem) -> Void)? = .none) where Connection: ConnectionType, Metadata: NSCoding { return connection.asyncWriteWithMetadata(YapItem(self, metadata), queue: queue, completion: completion) @@ -85,7 +85,7 @@ extension Sequence where - returns: an array where Persistables and Metadata with corresponding indexes in `self` and `metadata` are joined in a `YapItem` */ public func yapItems< - Metadatas, Metadata>(with metadata: Metadatas) -> [YapItem] where + Metadatas, Metadata>(with metadata: Metadatas) -> [YapItem] where Metadata: NSCoding, Metadatas: Sequence, Metadatas.Iterator.Element == Optional { @@ -99,7 +99,7 @@ extension Sequence where - returns: the receiver. */ public func writeWithMetadata< - WriteTransaction, Metadata>(_ transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] where + WriteTransaction, Metadata>(_ transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] where WriteTransaction: WriteTransactionType, Metadata: NSCoding { let items = yapItems(with: metadata) @@ -113,7 +113,7 @@ extension Sequence where - returns: the receiver. */ public func writeWithMetadata< - Connection, Metadata>(_ connection: Connection, metadata: [Metadata?]) -> [YapItem] where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?]) -> [YapItem] where Connection: ConnectionType, Metadata: NSCoding { let items = yapItems(with: metadata) @@ -127,7 +127,7 @@ extension Sequence where - returns: a closure which receives as an argument the receiver of this function. */ public func asyncWriteWithMetadata< - Connection, Metadata>(_ connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (([YapItem]) -> Void)? = .None) where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?], queue: DispatchQueue = DispatchQueue.main, completion: (([YapItem]) -> Void)? = .none) where Connection: ConnectionType, Metadata: NSCoding { let items = yapItems(with: metadata) diff --git a/Sources/Persistable_ValueWithValueMetadata.swift b/Sources/Persistable_ValueWithValueMetadata.swift index b59b119..3981edd 100644 --- a/Sources/Persistable_ValueWithValueMetadata.swift +++ b/Sources/Persistable_ValueWithValueMetadata.swift @@ -55,7 +55,7 @@ extension Persistable where - returns: a closure which receives as an argument the receiver of this function. */ public func asyncWriteWithMetadata< - Connection, Metadata>(_ connection: Connection, metadata: Metadata?, queue: dispatch_queue_t = dispatch_get_main_queue(), completion: ((YapItem) -> Void)? = .none) where + Connection, Metadata>(_ connection: Connection, metadata: Metadata?, queue: DispatchQueue = DispatchQueue.main, completion: ((YapItem) -> Void)? = .none) where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, @@ -93,7 +93,7 @@ extension Sequence where - returns: an array where Persistables and Metadata with corresponding indexes in `self` and `metadata` are joined in a `YapItem` */ public func yapItems< - Metadatas, Metadata>(with metadata: Metadatas) -> [YapItem] where + Metadatas, Metadata>(with metadata: Metadatas) -> [YapItem] where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata, @@ -109,7 +109,7 @@ extension Sequence where - returns: the receiver. */ public func writeWithMetadata< - WriteTransaction, Metadata>(_ transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] where + WriteTransaction, Metadata>(_ transaction: WriteTransaction, metadata: [Metadata?]) -> [YapItem] where WriteTransaction: WriteTransactionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, @@ -125,7 +125,7 @@ extension Sequence where - returns: the receiver. */ public func writeWithMetadata< - Connection, Metadata>(_ connection: Connection, metadata: [Metadata?]) -> [YapItem] where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?]) -> [YapItem] where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, @@ -141,7 +141,7 @@ extension Sequence where - returns: a closure which receives as an argument the receiver of this function. */ public func asyncWriteWithMetadata< - Connection, Metadata>(_ connection: Connection, metadata: [Metadata?], queue: dispatch_queue_t = dispatch_get_main_queue(), completion: (([YapItem]) -> Void)? = .None) where + Connection, Metadata>(_ connection: Connection, metadata: [Metadata?], queue: DispatchQueue = DispatchQueue.main, completion: (([YapItem]) -> Void)? = .none) where Connection: ConnectionType, Metadata: ValueCoding, Metadata.Coder: NSCoding, diff --git a/Sources/Read.swift b/Sources/Read.swift index 4ac8e0c..d228c1f 100644 --- a/Sources/Read.swift +++ b/Sources/Read.swift @@ -118,7 +118,7 @@ extension Readable where ItemType: Persistable { - func sync(_ block: (Database.Connection.ReadTransaction) -> T) -> T { + func sync(_ block: @escaping (Database.Connection.ReadTransaction) -> T) -> T { if let transaction = transaction { return block(transaction) } diff --git a/Sources/YapDB.swift b/Sources/YapDB.swift index ccd11d3..4cdfee7 100644 --- a/Sources/YapDB.swift +++ b/Sources/YapDB.swift @@ -373,7 +373,7 @@ extension YapDB { func registerInDatabase(_ database: YapDatabase, withConnection connection: YapDatabaseConnection? = .none) { if (database.registeredExtension(searchName) as? YapDatabaseFullTextSearch) == .none { - let fullTextSearch = YapDatabaseFullTextSearch(columnNames: columnNames, handler: handler.object, versionTag: version) + let fullTextSearch = YapDatabaseFullTextSearch(columnNames: columnNames, options: nil, handler: handler.object, versionTag: version) if let connection = connection { database.register(fullTextSearch, withName: searchName, connection: connection) } diff --git a/Sources/YapDatabaseExtensions.swift b/Sources/YapDatabaseExtensions.swift index 9bddafd..365d32f 100644 --- a/Sources/YapDatabaseExtensions.swift +++ b/Sources/YapDatabaseExtensions.swift @@ -109,7 +109,7 @@ public struct YapDB { let path = pathToDatabase(.cachesDirectory, name: (file as NSString).lastPathComponent, suffix: test.trimmingCharacters(in: CharacterSet(charactersIn: "()"))) assert(!path.isEmpty, "Path should not be empty.") do { - try FileManager.default.removeItem(atPath: path) + try FileManager.`default`.removeItem(atPath: path) } catch { } @@ -193,10 +193,6 @@ Identifier for your String identifiers. */ public typealias Identifier = String -extension Identifier: CustomStringConvertible { - public var description: String { return self } -} - // MARK: - Persistable /** @@ -339,7 +335,7 @@ public protocol ConnectionType { - parameter block: a closure which receives YapDatabaseReadTransaction and returns T - returns: An instance of T */ - func read(_ block: (ReadTransaction) -> T) -> T + func read(_ block: @escaping (ReadTransaction) -> T) -> T /** Synchronously writes to the database on the connection. The closure receives @@ -352,7 +348,7 @@ public protocol ConnectionType { - parameter block: a closure which receives YapDatabaseReadWriteTransaction and returns T - returns: An instance of T */ - func write(_ block: (WriteTransaction) -> T) -> T + func write(_ block: @escaping (WriteTransaction) -> T) -> T /** Asynchronously reads from the database on the connection. The closure receives @@ -368,7 +364,7 @@ public protocol ConnectionType { - parameter queue: a dispatch_queue_t, defaults to main queue, can be ommitted in most cases. - parameter completion: a closure which receives T and returns Void. */ - func asyncRead(_ block: (ReadTransaction) -> T, queue: DispatchQueue, completion: (T) -> Void) + func asyncRead(_ block: @escaping (ReadTransaction) -> T, queue: DispatchQueue, completion: @escaping (T) -> Void) /** Asynchronously writes to the database on the connection. The closure receives @@ -384,7 +380,7 @@ public protocol ConnectionType { - parameter queue: a dispatch_queue_t, defaults to main queue, can be ommitted in most cases. - parameter completion: a closure which receives T and returns Void. */ - func asyncWrite(_ block: (WriteTransaction) -> T, queue: DispatchQueue, completion: ((T) -> Void)?) + func asyncWrite(_ block: @escaping (WriteTransaction) -> T, queue: DispatchQueue, completion: ((T) -> Void)?) /** Execute a read/write block inside a `NSOperation`. The block argument receives a @@ -400,7 +396,7 @@ public protocol ConnectionType { - parameter block: a closure of type (YapDatabaseReadWriteTransaction) -> Void - returns: an `NSOperation`. */ - func writeBlockOperation(_ block: (WriteTransaction) -> Void) -> Operation + func writeBlockOperation(_ block: @escaping (WriteTransaction) -> Void) -> Operation } /// A facade interface for a database. @@ -607,7 +603,7 @@ extension YapDB.Index: ValueCoding { // MARK: Coders -public final class YapDBIndexCoder: NSObject, NSCoding, CodingType { +public final class YapDBIndexCoder: NSObject, NSCoding, CodingProtocol { public let value: YapDB.Index public init(_ v: YapDB.Index) { @@ -640,8 +636,8 @@ public typealias ValueMetadataPersistable = Persistable @available(*, unavailable, renamed: "ValueCoding") public typealias Saveable = ValueCoding -@available(*, unavailable, renamed: "CodingType") -public typealias Archiver = CodingType +@available(*, unavailable, renamed: "CodingProtocol") +public typealias Archiver = CodingProtocol diff --git a/Tests/Models.swift b/Tests/Models.swift index f161786..1faf202 100644 --- a/Tests/Models.swift +++ b/Tests/Models.swift @@ -253,7 +253,7 @@ extension Manager.Metadata: ValueCoding { // MARK: - Coders -open class BarcodeCoder: NSObject, NSCoding, CodingType { +open class BarcodeCoder: NSObject, NSCoding, CodingProtocol { open let value: Barcode public required init(_ v: Barcode) { @@ -293,7 +293,7 @@ open class BarcodeCoder: NSObject, NSCoding, CodingType { } } -open class ProductCategoryCoder: NSObject, NSCoding, CodingType { +open class ProductCategoryCoder: NSObject, NSCoding, CodingProtocol { open let value: Product.Category public required init(_ v: Product.Category) { @@ -312,7 +312,7 @@ open class ProductCategoryCoder: NSObject, NSCoding, CodingType { } } -open class ProductMetadataCoder: NSObject, NSCoding, CodingType { +open class ProductMetadataCoder: NSObject, NSCoding, CodingProtocol { open let value: Product.Metadata public required init(_ v: Product.Metadata) { @@ -329,7 +329,7 @@ open class ProductMetadataCoder: NSObject, NSCoding, CodingType { } } -open class ProductCoder: NSObject, NSCoding, CodingType { +open class ProductCoder: NSObject, NSCoding, CodingProtocol { open let value: Product public required init(_ v: Product) { @@ -350,7 +350,7 @@ open class ProductCoder: NSObject, NSCoding, CodingType { } } -open class InventoryCoder: NSObject, NSCoding, CodingType { +open class InventoryCoder: NSObject, NSCoding, CodingProtocol { open let value: Inventory public required init(_ v: Inventory) { @@ -368,7 +368,7 @@ open class InventoryCoder: NSObject, NSCoding, CodingType { } -open class ManagerMetadataCoder: NSObject, NSCoding, CodingType { +open class ManagerMetadataCoder: NSObject, NSCoding, CodingProtocol { open let value: Manager.Metadata public required init(_ v: Manager.Metadata) { diff --git a/Tests/ObjectWithNoMetadataTests.swift b/Tests/ObjectWithNoMetadataTests.swift index 158f10d..720e9f8 100644 --- a/Tests/ObjectWithNoMetadataTests.swift +++ b/Tests/ObjectWithNoMetadataTests.swift @@ -50,7 +50,7 @@ class ObjectWithNoMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) operationQueue = OperationQueue() } diff --git a/Tests/ObjectWithObjectMetadataTests.swift b/Tests/ObjectWithObjectMetadataTests.swift index 878f782..e2b971d 100644 --- a/Tests/ObjectWithObjectMetadataTests.swift +++ b/Tests/ObjectWithObjectMetadataTests.swift @@ -53,7 +53,7 @@ class ObjectWithObjectMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) operationQueue = OperationQueue() } diff --git a/Tests/ObjectWithValueMetadataTests.swift b/Tests/ObjectWithValueMetadataTests.swift index da4778b..9c1e92a 100644 --- a/Tests/ObjectWithValueMetadataTests.swift +++ b/Tests/ObjectWithValueMetadataTests.swift @@ -53,7 +53,7 @@ class ObjectWithValueMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) operationQueue = OperationQueue() } diff --git a/Tests/ValueWithNoMetadataTests.swift b/Tests/ValueWithNoMetadataTests.swift index 032e2f0..63a2a06 100644 --- a/Tests/ValueWithNoMetadataTests.swift +++ b/Tests/ValueWithNoMetadataTests.swift @@ -52,7 +52,7 @@ class ValueWithNoMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) operationQueue = OperationQueue() } diff --git a/Tests/ValueWithObjectMetadataTests.swift b/Tests/ValueWithObjectMetadataTests.swift index 1f7fb37..62e1cc9 100644 --- a/Tests/ValueWithObjectMetadataTests.swift +++ b/Tests/ValueWithObjectMetadataTests.swift @@ -53,7 +53,7 @@ class ValueWithObjectMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) operationQueue = OperationQueue() } diff --git a/Tests/ValueWithValueMetadataTests.swift b/Tests/ValueWithValueMetadataTests.swift index 7569cff..9269928 100644 --- a/Tests/ValueWithValueMetadataTests.swift +++ b/Tests/ValueWithValueMetadataTests.swift @@ -53,7 +53,7 @@ class ValueWithValueMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) operationQueue = OperationQueue() } diff --git a/Tests/YapDatabaseExtensionsTests.swift b/Tests/YapDatabaseExtensionsTests.swift index 2521d19..ea3dc86 100644 --- a/Tests/YapDatabaseExtensionsTests.swift +++ b/Tests/YapDatabaseExtensionsTests.swift @@ -141,7 +141,7 @@ class YapDatabaseConnectionTests: ReadWriteBaseTests { override func setUp() { super.setUp() - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) operationQueue = OperationQueue() } From 3d599c3cb6a3121131b0fea4ad5bcb4583e7463d Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 00:26:57 -0800 Subject: [PATCH 21/54] run the Swift 3 converter again --- Tests/Models.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Models.swift b/Tests/Models.swift index 1faf202..2de5718 100644 --- a/Tests/Models.swift +++ b/Tests/Models.swift @@ -339,14 +339,14 @@ open class ProductCoder: NSObject, NSCoding, CodingProtocol { public required init?(coder aDecoder: NSCoder) { let identifier = aDecoder.decodeObject(forKey: "identifier") as! String let name = aDecoder.decodeObject(forKey: "name") as! String - let barcode = Barcode.decode(aDecoder.decodeObjectForKey("barcode")) + let barcode = Barcode.decode(aDecoder.decodeObject(forKey: "barcode")) value = Product(identifier: identifier, name: name, barcode: barcode!) } open func encode(with aCoder: NSCoder) { aCoder.encodeObject(value.identifier, forKey: "identifier") aCoder.encode(value.name, forKey: "name") - aCoder.encodeObject(value.barcode.encoded, forKey: "barcode") + aCoder.encode(value.barcode.encoded, forKey: "barcode") } } @@ -358,12 +358,12 @@ open class InventoryCoder: NSObject, NSCoding, CodingProtocol { } public required init?(coder aDecoder: NSCoder) { - let product = Product.decode(aDecoder.decodeObjectForKey("product")) + let product = Product.decode(aDecoder.decodeObject(forKey: "product")) value = Inventory(product: product!) } open func encode(with aCoder: NSCoder) { - aCoder.encodeObject(value.product.encoded, forKey: "product") + aCoder.encode(value.product.encoded, forKey: "product") } } From 098183e48344f416661037ce3ccd174977af0c2f Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 00:32:11 -0800 Subject: [PATCH 22/54] fix build warnings about unused return values --- Sources/Persistable_ObjectWithNoMetadata.swift | 4 ++-- Sources/Persistable_ObjectWithObjectMetadata.swift | 4 ++-- Sources/Persistable_ObjectWithValueMetadata.swift | 4 ++-- Sources/Persistable_ValueWithNoMetadata.swift | 4 ++-- Sources/Persistable_ValueWithObjectMetadata.swift | 4 ++-- Sources/Persistable_ValueWithValueMetadata.swift | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/Persistable_ObjectWithNoMetadata.swift b/Sources/Persistable_ObjectWithNoMetadata.swift index fc810c7..805d3ca 100644 --- a/Sources/Persistable_ObjectWithNoMetadata.swift +++ b/Sources/Persistable_ObjectWithNoMetadata.swift @@ -53,7 +53,7 @@ extension Persistable where - returns: an `NSOperation` */ public func writeOperation(_ connection: Connection) -> Operation { - return BlockOperation { connection.write(self) } + return BlockOperation { _ = connection.write(self) } } } @@ -98,7 +98,7 @@ extension Sequence where - returns: an `NSOperation` */ public func writeOperation(_ connection: Connection) -> Operation { - return BlockOperation { connection.write(self) } + return BlockOperation { _ = connection.write(self) } } } diff --git a/Sources/Persistable_ObjectWithObjectMetadata.swift b/Sources/Persistable_ObjectWithObjectMetadata.swift index b128acf..114b6ce 100644 --- a/Sources/Persistable_ObjectWithObjectMetadata.swift +++ b/Sources/Persistable_ObjectWithObjectMetadata.swift @@ -64,7 +64,7 @@ extension Persistable where Connection, Metadata>(_ connection: Connection, metadata: Metadata?) -> Operation where Connection: ConnectionType, Metadata: NSCoding { - return BlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } + return BlockOperation { _ = connection.writeWithMetadata(YapItem(self, metadata)) } } } @@ -140,7 +140,7 @@ extension Sequence where Connection: ConnectionType, Metadata: NSCoding { let items = yapItems(with: metadata) - return BlockOperation { connection.writeWithMetadata(items) } + return BlockOperation { _ = connection.writeWithMetadata(items) } } } diff --git a/Sources/Persistable_ObjectWithValueMetadata.swift b/Sources/Persistable_ObjectWithValueMetadata.swift index d19d97c..6b7cd35 100644 --- a/Sources/Persistable_ObjectWithValueMetadata.swift +++ b/Sources/Persistable_ObjectWithValueMetadata.swift @@ -73,7 +73,7 @@ extension Persistable where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { - return BlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } + return BlockOperation { _ = connection.writeWithMetadata(YapItem(self, metadata)) } } } @@ -159,7 +159,7 @@ extension Sequence where Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { let items = yapItems(with: metadata) - return BlockOperation { connection.writeWithMetadata(items) } + return BlockOperation { _ = connection.writeWithMetadata(items) } } } diff --git a/Sources/Persistable_ValueWithNoMetadata.swift b/Sources/Persistable_ValueWithNoMetadata.swift index 7613851..7988f65 100644 --- a/Sources/Persistable_ValueWithNoMetadata.swift +++ b/Sources/Persistable_ValueWithNoMetadata.swift @@ -55,7 +55,7 @@ extension Persistable where - returns: an `NSOperation` */ public func writeOperation(_ connection: Connection) -> Operation { - return BlockOperation { connection.write(self) } + return BlockOperation { _ = connection.write(self) } } } @@ -102,7 +102,7 @@ extension Sequence where - returns: an `NSOperation` */ public func writeOperation(_ connection: Connection) -> Operation { - return BlockOperation { connection.write(self) } + return BlockOperation { _ = connection.write(self) } } } diff --git a/Sources/Persistable_ValueWithObjectMetadata.swift b/Sources/Persistable_ValueWithObjectMetadata.swift index 7995200..1725c2c 100644 --- a/Sources/Persistable_ValueWithObjectMetadata.swift +++ b/Sources/Persistable_ValueWithObjectMetadata.swift @@ -67,7 +67,7 @@ extension Persistable where Connection, Metadata>(_ connection: Connection, metadata: Metadata?) -> Operation where Connection: ConnectionType, Metadata: NSCoding { - return BlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } + return BlockOperation { _ = connection.writeWithMetadata(YapItem(self, metadata)) } } } @@ -145,7 +145,7 @@ extension Sequence where Connection: ConnectionType, Metadata: NSCoding { let items = yapItems(with: metadata) - return BlockOperation { connection.writeWithMetadata(items) } + return BlockOperation { _ = connection.writeWithMetadata(items) } } } diff --git a/Sources/Persistable_ValueWithValueMetadata.swift b/Sources/Persistable_ValueWithValueMetadata.swift index 3981edd..1db038f 100644 --- a/Sources/Persistable_ValueWithValueMetadata.swift +++ b/Sources/Persistable_ValueWithValueMetadata.swift @@ -75,7 +75,7 @@ extension Persistable where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { - return BlockOperation { connection.writeWithMetadata(YapItem(self, metadata)) } + return BlockOperation { _ = connection.writeWithMetadata(YapItem(self, metadata)) } } } @@ -163,7 +163,7 @@ extension Sequence where Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { let items = yapItems(with: metadata) - return BlockOperation { connection.writeWithMetadata(items) } + return BlockOperation { _ = connection.writeWithMetadata(items) } } } From 2ca966c546b1887e9c5282e8c9ef6032bff098ad Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 00:40:25 -0800 Subject: [PATCH 23/54] renames suggested by Xcode --- Tests/Models.swift | 12 ++++++------ Tests/ObjectWithNoMetadataTests.swift | 4 ++-- Tests/ObjectWithObjectMetadataTests.swift | 4 ++-- Tests/ObjectWithValueMetadataTests.swift | 4 ++-- Tests/ReadWriteTests.swift | 4 ++-- Tests/ValueWithNoMetadataTests.swift | 4 ++-- Tests/ValueWithObjectMetadataTests.swift | 4 ++-- Tests/ValueWithValueMetadataTests.swift | 4 ++-- Tests/YapDatabaseExtensionsTests.swift | 12 ++++++------ 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Tests/Models.swift b/Tests/Models.swift index 2de5718..875348d 100644 --- a/Tests/Models.swift +++ b/Tests/Models.swift @@ -61,12 +61,12 @@ open class NamedEntity: NSObject, NSCoding { } public required init?(coder aDecoder: NSCoder) { - identifier = aDecoder.decodeObjectForKey("identifier") as! Identifier + identifier = aDecoder.decodeObject(forKey: "identifier") as! Identifier name = aDecoder.decodeObject(forKey: "name") as! String } open func encode(with aCoder: NSCoder) { - aCoder.encodeObject(identifier, forKey: "identifier") + aCoder.encode(identifier, forKey: "identifier") aCoder.encode(name, forKey: "name") } } @@ -344,7 +344,7 @@ open class ProductCoder: NSObject, NSCoding, CodingProtocol { } open func encode(with aCoder: NSCoder) { - aCoder.encodeObject(value.identifier, forKey: "identifier") + aCoder.encode(value.identifier, forKey: "identifier") aCoder.encode(value.name, forKey: "name") aCoder.encode(value.barcode.encoded, forKey: "barcode") } @@ -389,7 +389,7 @@ open class ManagerMetadataCoder: NSObject, NSCoding, CodingProtocol { public func products() -> YapDB.Fetch { - let grouping: YapDB.View.Grouping = .ByMetadata({ (_, collection, key, metadata) -> String! in + let grouping: YapDB.View.Grouping = .byMetadata({ (_, collection, key, metadata) -> String! in if collection == Product.collection { if let metadata = Product.Metadata.decode(metadata) { return "category: \(metadata.categoryIdentifier)" @@ -398,7 +398,7 @@ public func products() -> YapDB.Fetch { return nil }) - let sorting: YapDB.View.Sorting = .ByObject({ (_, group, collection1, key1, object1, collection2, key2, object2) -> NSComparisonResult in + let sorting: YapDB.View.Sorting = .ByObject({ (_, group, collection1, key1, object1, collection2, key2, object2) -> ComparisonResult in if let product1 = Product.decode(object1) { if let product2 = Product.decode(object2) { return product1.name.caseInsensitiveCompare(product2.name) @@ -413,7 +413,7 @@ public func products() -> YapDB.Fetch { sorting: sorting, collections: [Product.collection]) - return .View(view) + return .view(view) } diff --git a/Tests/ObjectWithNoMetadataTests.swift b/Tests/ObjectWithNoMetadataTests.swift index 720e9f8..46cf8f3 100644 --- a/Tests/ObjectWithNoMetadataTests.swift +++ b/Tests/ObjectWithNoMetadataTests.swift @@ -100,7 +100,7 @@ class ObjectWithNoMetadataTests: XCTestCase { func checkTransactionDidWriteItems(_ result: [TypeUnderTest]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) XCTAssertEqual(Set(result), Set(items)) @@ -713,7 +713,7 @@ class Persistable_Write_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { operationQueue.addOperation(operation) waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sort()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertTrue(connection.didWrite) } diff --git a/Tests/ObjectWithObjectMetadataTests.swift b/Tests/ObjectWithObjectMetadataTests.swift index e2b971d..f594eca 100644 --- a/Tests/ObjectWithObjectMetadataTests.swift +++ b/Tests/ObjectWithObjectMetadataTests.swift @@ -110,7 +110,7 @@ class ObjectWithObjectMetadataTests: XCTestCase { func checkTransactionDidWriteItems(_ result: [YapItem]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sorted()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) XCTAssertEqual(Set(result.map({$0.value})), Set(items)) @@ -725,7 +725,7 @@ class Persistable_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataT operationQueue.addOperation(operation) waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sorted()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertTrue(connection.didWrite) } diff --git a/Tests/ObjectWithValueMetadataTests.swift b/Tests/ObjectWithValueMetadataTests.swift index 9c1e92a..538ba3d 100644 --- a/Tests/ObjectWithValueMetadataTests.swift +++ b/Tests/ObjectWithValueMetadataTests.swift @@ -114,7 +114,7 @@ class ObjectWithValueMetadataTests: XCTestCase { func checkTransactionDidWriteItems(_ result: [YapItem]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sorted()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) XCTAssertEqual(Set(result.map({$0.value})), Set(items)) @@ -729,7 +729,7 @@ class Persistable_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTes operationQueue.addOperation(operation) waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sorted()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertTrue(connection.didWrite) } diff --git a/Tests/ReadWriteTests.swift b/Tests/ReadWriteTests.swift index b672166..c43d3e1 100644 --- a/Tests/ReadWriteTests.swift +++ b/Tests/ReadWriteTests.swift @@ -70,7 +70,7 @@ class ReadTests: ReadWriteBaseTests { func test__initialize_with_transaction() { let db = YapDB.testDatabase() let connection = db.makeNewConnection() - connection.readWithBlock { transaction in + connection.read { transaction in self.reader = Read(transaction) XCTAssertNotNil(self.reader) } @@ -95,7 +95,7 @@ class ReadTests: ReadWriteBaseTests { func test__getting_reader_from_persistable_with_transaction() { let db = YapDB.testDatabase() let connection = db.makeNewConnection() - connection.readWithBlock { transaction in + connection.read { transaction in self.reader = Employee.read(transaction) XCTAssertNotNil(self.reader) } diff --git a/Tests/ValueWithNoMetadataTests.swift b/Tests/ValueWithNoMetadataTests.swift index 63a2a06..8bb5534 100644 --- a/Tests/ValueWithNoMetadataTests.swift +++ b/Tests/ValueWithNoMetadataTests.swift @@ -102,7 +102,7 @@ class ValueWithNoMetadataTests: XCTestCase { func checkTransactionDidWriteItems(_ result: [TypeUnderTest]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sorted()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) XCTAssertEqual(Set(result), Set(items)) @@ -715,7 +715,7 @@ class Persistable_Write_ValueWithNoMetadataTests: ValueWithNoMetadataTests { operationQueue.addOperation(operation) waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sorted()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertTrue(connection.didWrite) } diff --git a/Tests/ValueWithObjectMetadataTests.swift b/Tests/ValueWithObjectMetadataTests.swift index 62e1cc9..ecb3d61 100644 --- a/Tests/ValueWithObjectMetadataTests.swift +++ b/Tests/ValueWithObjectMetadataTests.swift @@ -132,7 +132,7 @@ class ValueWithObjectMetadataTests: XCTestCase { func checkTransactionDidWriteItems(_ result: [YapItem]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sorted()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) XCTAssertEqual(Set(result.map({$0.value})), Set(items)) @@ -862,7 +862,7 @@ class Persistable_Write_ValueWithObjectMetadataTests: ValueWithObjectMetadataTes operationQueue.addOperation(operation) waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sorted()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertTrue(connection.didWrite) } diff --git a/Tests/ValueWithValueMetadataTests.swift b/Tests/ValueWithValueMetadataTests.swift index 9269928..e9b47e9 100644 --- a/Tests/ValueWithValueMetadataTests.swift +++ b/Tests/ValueWithValueMetadataTests.swift @@ -130,7 +130,7 @@ class ValueWithValueMetadataTests: XCTestCase { func checkTransactionDidWriteItems(_ result: [YapItem]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sorted()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) XCTAssertEqual(Set(result.map({$0.value})), Set(items)) @@ -859,7 +859,7 @@ class Persistable_Write_ValueWithValueMetadataTests: ValueWithValueMetadataTests operationQueue.addOperation(operation) waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sort(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sorted()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertTrue(connection.didWrite) } diff --git a/Tests/YapDatabaseExtensionsTests.swift b/Tests/YapDatabaseExtensionsTests.swift index ea3dc86..63206c1 100644 --- a/Tests/YapDatabaseExtensionsTests.swift +++ b/Tests/YapDatabaseExtensionsTests.swift @@ -66,7 +66,7 @@ class YapDatabaseReadTransactionTests: ReadWriteBaseTests { writeItemsToDatabase(db) let keys = db.makeNewConnection().read { $0.keysInCollection(Employee.collection) } XCTAssertNotNil(keys) - XCTAssertEqual(keys.sort(), items.map { $0.key }.sort()) + XCTAssertEqual(keys.sorted(), items.map { $0.key }.sorted()) } func test__read_at_index_returns_nil_with_empty_db() { @@ -101,7 +101,7 @@ class YapDatabaseReadWriteTransactionTests: ReadWriteBaseTests { func test__write_at_index_without_metadata() { let db = YapDB.testDatabase() - db.makeNewConnection().readWriteWithBlock { transaction in + db.makeNewConnection().readWrite { transaction in transaction.writeAtIndex(self.index, object: self.item) } let written = Employee.read(db).atIndex(index) @@ -126,7 +126,7 @@ class YapDatabaseReadWriteTransactionTests: ReadWriteBaseTests { db.makeNewConnection().write(items) XCTAssertNotNil(Employee.read(db).atIndex(index)) - db.makeNewConnection().readWriteWithBlock { transaction in + db.makeNewConnection().readWrite { transaction in transaction.removeAtIndexes(self.indexes) } @@ -197,7 +197,7 @@ class YapDatabaseConnectionTests: ReadWriteBaseTests { operationQueue.addOperation(operation) waitForExpectations(timeout: 3.0, handler: nil) - XCTAssertTrue(operation.finished) + XCTAssertTrue(operation.isFinished) XCTAssertTrue(didExecuteWithTransaction) } } @@ -280,11 +280,11 @@ class ValueCodingTests: XCTestCase { func test__index_is_codable() { let db = YapDB.testDatabase() - db.makeNewConnection().readWriteWithBlock { transaction in + db.makeNewConnection().readWrite { transaction in transaction.setObject(self.index.encoded, forKey: "test-index", inCollection: "test-index-collection") } - let unarchived = YapDB.Index.decode(db.makeNewConnection().read { $0.objectForKey("test-index", inCollection: "test-index-collection") }) + let unarchived = YapDB.Index.decode(db.makeNewConnection().read { $0.object(forKey: "test-index", inCollection: "test-index-collection") }) XCTAssertNotNil(unarchived) XCTAssertEqual(unarchived!, index) } From 8e29034646e97f8f970d4041854307f8a209b1f0 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 00:44:00 -0800 Subject: [PATCH 24/54] prefixUpTo renames --- Tests/ObjectWithNoMetadataTests.swift | 4 ++-- Tests/ObjectWithObjectMetadataTests.swift | 4 ++-- Tests/ObjectWithValueMetadataTests.swift | 4 ++-- Tests/ValueWithNoMetadataTests.swift | 4 ++-- Tests/ValueWithObjectMetadataTests.swift | 4 ++-- Tests/ValueWithValueMetadataTests.swift | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/ObjectWithNoMetadataTests.swift b/Tests/ObjectWithNoMetadataTests.swift index 46cf8f3..7ef19a9 100644 --- a/Tests/ObjectWithNoMetadataTests.swift +++ b/Tests/ObjectWithNoMetadataTests.swift @@ -554,7 +554,7 @@ class Persistable_Read_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { reader = Read(readTransaction) let (items, missing) = reader.filterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.identifier }, items.prefixUpTo(1).map { $0.identifier }) + XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -633,7 +633,7 @@ class Persistable_Read_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { let (items, missing) = reader.filterExisting(keys) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.identifier }, items.prefixUpTo(1).map { $0.identifier }) + XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } diff --git a/Tests/ObjectWithObjectMetadataTests.swift b/Tests/ObjectWithObjectMetadataTests.swift index f594eca..1995656 100644 --- a/Tests/ObjectWithObjectMetadataTests.swift +++ b/Tests/ObjectWithObjectMetadataTests.swift @@ -566,7 +566,7 @@ class Persistable_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe reader = Read(readTransaction) let (items, missing): ([YapItem], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.value.identifier }, items.prefixUpTo(1).map { $0.value.identifier }) + XCTAssertEqual(items.map { $0.value.identifier }, items.prefix(upTo: 1).map { $0.value.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -645,7 +645,7 @@ class Persistable_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe let (items, missing) = reader.filterExisting(keys) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.identifier }, items.prefixUpTo(1).map { $0.identifier }) + XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } diff --git a/Tests/ObjectWithValueMetadataTests.swift b/Tests/ObjectWithValueMetadataTests.swift index 538ba3d..e07749f 100644 --- a/Tests/ObjectWithValueMetadataTests.swift +++ b/Tests/ObjectWithValueMetadataTests.swift @@ -570,7 +570,7 @@ class Persistable_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest reader = Read(readTransaction) let (items, missing): ([YapItem], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.value.identifier }, items.prefixUpTo(1).map { $0.value.identifier }) + XCTAssertEqual(items.map { $0.value.identifier }, items.prefix(upTo: 1).map { $0.value.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -649,7 +649,7 @@ class Persistable_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest let (items, missing) = reader.filterExisting(keys) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.identifier }, items.prefixUpTo(1).map { $0.identifier }) + XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } diff --git a/Tests/ValueWithNoMetadataTests.swift b/Tests/ValueWithNoMetadataTests.swift index 8bb5534..3d14532 100644 --- a/Tests/ValueWithNoMetadataTests.swift +++ b/Tests/ValueWithNoMetadataTests.swift @@ -556,7 +556,7 @@ class Persistable_Read_ValueWithNoMetadataTests: ValueWithNoMetadataTests { reader = Read(readTransaction) let (items, missing) = reader.filterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.identifier }, items.prefixUpTo(1).map { $0.identifier }) + XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -635,7 +635,7 @@ class Persistable_Read_ValueWithNoMetadataTests: ValueWithNoMetadataTests { let (items, missing) = reader.filterExisting(keys) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.identifier }, items.prefixUpTo(1).map { $0.identifier }) + XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } diff --git a/Tests/ValueWithObjectMetadataTests.swift b/Tests/ValueWithObjectMetadataTests.swift index ecb3d61..5743130 100644 --- a/Tests/ValueWithObjectMetadataTests.swift +++ b/Tests/ValueWithObjectMetadataTests.swift @@ -652,7 +652,7 @@ class Persistable_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest reader = Read(readTransaction) let (items, missing): ([YapItem], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.value.identifier }, items.prefixUpTo(1).map { $0.value.identifier }) + XCTAssertEqual(items.map { $0.value.identifier }, items.prefix(upTo: 1).map { $0.value.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -731,7 +731,7 @@ class Persistable_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest let (items, missing) = reader.filterExisting(keys) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.identifier }, items.prefixUpTo(1).map { $0.identifier }) + XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } diff --git a/Tests/ValueWithValueMetadataTests.swift b/Tests/ValueWithValueMetadataTests.swift index e9b47e9..6dcfce2 100644 --- a/Tests/ValueWithValueMetadataTests.swift +++ b/Tests/ValueWithValueMetadataTests.swift @@ -649,7 +649,7 @@ class Persistable_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests reader = Read(readTransaction) let (items, missing): ([YapItem], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.value.identifier }, items.prefixUpTo(1).map { $0.value.identifier }) + XCTAssertEqual(items.map { $0.value.identifier }, items.prefix(upTo: 1).map { $0.value.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } @@ -728,7 +728,7 @@ class Persistable_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests let (items, missing) = reader.filterExisting(keys) XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) - XCTAssertEqual(items.map { $0.identifier }, items.prefixUpTo(1).map { $0.identifier }) + XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) XCTAssertEqual(missing, Array(keys.suffixFrom(1))) } From 4dbbc7e6191d263534723fa8710423b792c28a27 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 00:44:25 -0800 Subject: [PATCH 25/54] add @escaping to TestableConnection block parameters --- Tests/Support.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Support.swift b/Tests/Support.swift index 40ed22b..b0d5f66 100644 --- a/Tests/Support.swift +++ b/Tests/Support.swift @@ -118,12 +118,12 @@ class TestableConnection { extension TestableConnection: ConnectionType { - func read(_ block: (TestableReadTransaction) -> T) -> T { + func read(_ block: @escaping (TestableReadTransaction) -> T) -> T { didRead = true return block(readTransaction) } - func write(_ block: (TestableWriteTransaction) -> T) -> T { + func write(_ block: @escaping (TestableWriteTransaction) -> T) -> T { didWrite = true return block(writeTransaction) } From b90261dd739e0af497a57f8f20f40288d711843b Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 00:45:21 -0800 Subject: [PATCH 26/54] suffixFrom renames --- Tests/ObjectWithNoMetadataTests.swift | 4 ++-- Tests/ObjectWithObjectMetadataTests.swift | 4 ++-- Tests/ObjectWithValueMetadataTests.swift | 4 ++-- Tests/ValueWithNoMetadataTests.swift | 4 ++-- Tests/ValueWithObjectMetadataTests.swift | 4 ++-- Tests/ValueWithValueMetadataTests.swift | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/ObjectWithNoMetadataTests.swift b/Tests/ObjectWithNoMetadataTests.swift index 7ef19a9..c7322c9 100644 --- a/Tests/ObjectWithNoMetadataTests.swift +++ b/Tests/ObjectWithNoMetadataTests.swift @@ -555,7 +555,7 @@ class Persistable_Read_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { let (items, missing) = reader.filterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) - XCTAssertEqual(missing, Array(keys.suffixFrom(1))) + XCTAssertEqual(missing, Array(keys.suffix(from: 1))) } // Reading - With Connection @@ -634,7 +634,7 @@ class Persistable_Read_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) - XCTAssertEqual(missing, Array(keys.suffixFrom(1))) + XCTAssertEqual(missing, Array(keys.suffix(from: 1))) } } diff --git a/Tests/ObjectWithObjectMetadataTests.swift b/Tests/ObjectWithObjectMetadataTests.swift index 1995656..20c0e11 100644 --- a/Tests/ObjectWithObjectMetadataTests.swift +++ b/Tests/ObjectWithObjectMetadataTests.swift @@ -567,7 +567,7 @@ class Persistable_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe let (items, missing): ([YapItem], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) XCTAssertEqual(items.map { $0.value.identifier }, items.prefix(upTo: 1).map { $0.value.identifier }) - XCTAssertEqual(missing, Array(keys.suffixFrom(1))) + XCTAssertEqual(missing, Array(keys.suffix(from: 1))) } // Reading - With Connection @@ -646,7 +646,7 @@ class Persistable_Read_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataTe XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) - XCTAssertEqual(missing, Array(keys.suffixFrom(1))) + XCTAssertEqual(missing, Array(keys.suffix(from: 1))) } } diff --git a/Tests/ObjectWithValueMetadataTests.swift b/Tests/ObjectWithValueMetadataTests.swift index e07749f..1296ebb 100644 --- a/Tests/ObjectWithValueMetadataTests.swift +++ b/Tests/ObjectWithValueMetadataTests.swift @@ -571,7 +571,7 @@ class Persistable_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest let (items, missing): ([YapItem], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) XCTAssertEqual(items.map { $0.value.identifier }, items.prefix(upTo: 1).map { $0.value.identifier }) - XCTAssertEqual(missing, Array(keys.suffixFrom(1))) + XCTAssertEqual(missing, Array(keys.suffix(from: 1))) } // Reading - With Connection @@ -650,7 +650,7 @@ class Persistable_Read_ObjectWithValueMetadataTests: ObjectWithValueMetadataTest XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) - XCTAssertEqual(missing, Array(keys.suffixFrom(1))) + XCTAssertEqual(missing, Array(keys.suffix(from: 1))) } } diff --git a/Tests/ValueWithNoMetadataTests.swift b/Tests/ValueWithNoMetadataTests.swift index 3d14532..735bf9f 100644 --- a/Tests/ValueWithNoMetadataTests.swift +++ b/Tests/ValueWithNoMetadataTests.swift @@ -557,7 +557,7 @@ class Persistable_Read_ValueWithNoMetadataTests: ValueWithNoMetadataTests { let (items, missing) = reader.filterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) - XCTAssertEqual(missing, Array(keys.suffixFrom(1))) + XCTAssertEqual(missing, Array(keys.suffix(from: 1))) } // Reading - With Connection @@ -636,7 +636,7 @@ class Persistable_Read_ValueWithNoMetadataTests: ValueWithNoMetadataTests { XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) - XCTAssertEqual(missing, Array(keys.suffixFrom(1))) + XCTAssertEqual(missing, Array(keys.suffix(from: 1))) } } diff --git a/Tests/ValueWithObjectMetadataTests.swift b/Tests/ValueWithObjectMetadataTests.swift index 5743130..a9b8138 100644 --- a/Tests/ValueWithObjectMetadataTests.swift +++ b/Tests/ValueWithObjectMetadataTests.swift @@ -653,7 +653,7 @@ class Persistable_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest let (items, missing): ([YapItem], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) XCTAssertEqual(items.map { $0.value.identifier }, items.prefix(upTo: 1).map { $0.value.identifier }) - XCTAssertEqual(missing, Array(keys.suffixFrom(1))) + XCTAssertEqual(missing, Array(keys.suffix(from: 1))) } // Reading - With Connection @@ -732,7 +732,7 @@ class Persistable_Read_ValueWithObjectMetadataTests: ValueWithObjectMetadataTest XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) - XCTAssertEqual(missing, Array(keys.suffixFrom(1))) + XCTAssertEqual(missing, Array(keys.suffix(from: 1))) } } diff --git a/Tests/ValueWithValueMetadataTests.swift b/Tests/ValueWithValueMetadataTests.swift index 6dcfce2..282e6ec 100644 --- a/Tests/ValueWithValueMetadataTests.swift +++ b/Tests/ValueWithValueMetadataTests.swift @@ -650,7 +650,7 @@ class Persistable_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests let (items, missing): ([YapItem], [String]) = reader.withMetadataFilterExisting(keys) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) XCTAssertEqual(items.map { $0.value.identifier }, items.prefix(upTo: 1).map { $0.value.identifier }) - XCTAssertEqual(missing, Array(keys.suffixFrom(1))) + XCTAssertEqual(missing, Array(keys.suffix(from: 1))) } // Reading - With Connection @@ -729,7 +729,7 @@ class Persistable_Read_ValueWithValueMetadataTests: ValueWithValueMetadataTests XCTAssertTrue(connection.didRead) XCTAssertEqual(readTransaction.didReadAtIndexes.first!, indexes.first!) XCTAssertEqual(items.map { $0.identifier }, items.prefix(upTo: 1).map { $0.identifier }) - XCTAssertEqual(missing, Array(keys.suffixFrom(1))) + XCTAssertEqual(missing, Array(keys.suffix(from: 1))) } } From cff9ad447d2bcc149518e60882cea2a5951ac3e9 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 00:45:48 -0800 Subject: [PATCH 27/54] renames suggested by Xcode --- Tests/ObjectWithNoMetadataTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/ObjectWithNoMetadataTests.swift b/Tests/ObjectWithNoMetadataTests.swift index c7322c9..5cc55a4 100644 --- a/Tests/ObjectWithNoMetadataTests.swift +++ b/Tests/ObjectWithNoMetadataTests.swift @@ -100,7 +100,7 @@ class ObjectWithNoMetadataTests: XCTestCase { func checkTransactionDidWriteItems(_ result: [TypeUnderTest]) { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sorted()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertFalse(result.isEmpty) XCTAssertEqual(Set(result), Set(items)) @@ -713,7 +713,7 @@ class Persistable_Write_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { operationQueue.addOperation(operation) waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sort()) + XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.0.key }.sorted(), indexes.map { $0.key }.sorted()) XCTAssertEqual(writeTransaction.didWriteAtIndexes.map { $0.2 }.count, items.count) XCTAssertTrue(connection.didWrite) } From 36dbc9c8da881d64b39decd6c47ef8046cccbb7d Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 00:49:57 -0800 Subject: [PATCH 28/54] renaming enum cases for lowercase --- Tests/Models.swift | 4 ++-- Tests/ValueWithObjectMetadataTests.swift | 8 ++++---- Tests/ValueWithValueMetadataTests.swift | 8 ++++---- Tests/YapDatabaseExtensionsTests.swift | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Tests/Models.swift b/Tests/Models.swift index 875348d..a33dd32 100644 --- a/Tests/Models.swift +++ b/Tests/Models.swift @@ -398,13 +398,13 @@ public func products() -> YapDB.Fetch { return nil }) - let sorting: YapDB.View.Sorting = .ByObject({ (_, group, collection1, key1, object1, collection2, key2, object2) -> ComparisonResult in + let sorting: YapDB.View.Sorting = .byObject({ (_, group, collection1, key1, object1, collection2, key2, object2) -> ComparisonResult in if let product1 = Product.decode(object1) { if let product2 = Product.decode(object2) { return product1.name.caseInsensitiveCompare(product2.name) } } - return .OrderedSame + return .orderedSame }) let view = YapDB.View( diff --git a/Tests/ValueWithObjectMetadataTests.swift b/Tests/ValueWithObjectMetadataTests.swift index a9b8138..b6a0713 100644 --- a/Tests/ValueWithObjectMetadataTests.swift +++ b/Tests/ValueWithObjectMetadataTests.swift @@ -81,22 +81,22 @@ class ValueWithObjectMetadataTests: XCTestCase { Product( identifier: "vodka-123", name: "Belvidere", - barcode: .UPCA(1, 2, 3, 4) + barcode: .upca(1, 2, 3, 4) ), Product( identifier: "gin-123", name: "Boxer Gin", - barcode: .UPCA(5, 10, 15, 20) + barcode: .upca(5, 10, 15, 20) ), Product( identifier: "rum-123", name: "Mount Gay Rum", - barcode: .UPCA(12, 24, 39, 48) + barcode: .upca(12, 24, 39, 48) ), Product( identifier: "gin-234", name: "Monkey 47", - barcode: .UPCA(31, 62, 93, 124) + barcode: .upca(31, 62, 93, 124) ) ] diff --git a/Tests/ValueWithValueMetadataTests.swift b/Tests/ValueWithValueMetadataTests.swift index 282e6ec..3efce5f 100644 --- a/Tests/ValueWithValueMetadataTests.swift +++ b/Tests/ValueWithValueMetadataTests.swift @@ -80,7 +80,7 @@ class ValueWithValueMetadataTests: XCTestCase { item = TypeUnderTest( identifier: "vodka-123", name: "Belvidere", - barcode: .UPCA(1, 2, 3, 4) + barcode: .upca(1, 2, 3, 4) ) metadata = TypeUnderTest.Metadata(categoryIdentifier: 1) items = [ @@ -88,17 +88,17 @@ class ValueWithValueMetadataTests: XCTestCase { TypeUnderTest( identifier: "gin-123", name: "Boxer Gin", - barcode: .UPCA(5, 10, 15, 20) + barcode: .upca(5, 10, 15, 20) ), TypeUnderTest( identifier: "rum-123", name: "Mount Gay Rum", - barcode: .UPCA(12, 24, 39, 48) + barcode: .upca(12, 24, 39, 48) ), TypeUnderTest( identifier: "gin-234", name: "Monkey 47", - barcode: .UPCA(31, 62, 93, 124) + barcode: .upca(31, 62, 93, 124) ) ] metadatas = [ diff --git a/Tests/YapDatabaseExtensionsTests.swift b/Tests/YapDatabaseExtensionsTests.swift index 63206c1..8129640 100644 --- a/Tests/YapDatabaseExtensionsTests.swift +++ b/Tests/YapDatabaseExtensionsTests.swift @@ -240,7 +240,7 @@ class ValueCodingTests: XCTestCase { item = Product( identifier: "vodka-123", name: "Belvidere", - barcode: .UPCA(1, 2, 3, 4) + barcode: .upca(1, 2, 3, 4) ) metadata = Product.Metadata(categoryIdentifier: 1) items = [ @@ -248,17 +248,17 @@ class ValueCodingTests: XCTestCase { Product( identifier: "gin-123", name: "Boxer Gin", - barcode: .UPCA(5, 10, 15, 20) + barcode: .upca(5, 10, 15, 20) ), Product( identifier: "rum-123", name: "Mount Gay Rum", - barcode: .UPCA(12, 24, 39, 48) + barcode: .upca(12, 24, 39, 48) ), Product( identifier: "gin-234", name: "Monkey 47", - barcode: .UPCA(31, 62, 93, 124) + barcode: .upca(31, 62, 93, 124) ) ] metadatas = [ From 820c8287910bbde51627f048b439321b7aecc7af Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 01:06:49 -0800 Subject: [PATCH 29/54] Date is not NSCoding, NSDate is --- Tests/ObjectWithObjectMetadataTests.swift | 10 +++++----- Tests/ReadWriteTests.swift | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/ObjectWithObjectMetadataTests.swift b/Tests/ObjectWithObjectMetadataTests.swift index 20c0e11..dc41b2a 100644 --- a/Tests/ObjectWithObjectMetadataTests.swift +++ b/Tests/ObjectWithObjectMetadataTests.swift @@ -13,7 +13,7 @@ import XCTest class ObjectWithObjectMetadataTests: XCTestCase { typealias TypeUnderTest = Employee - typealias MetadataTypeUnderTest = Date + typealias MetadataTypeUnderTest = NSDate var item: TypeUnderTest! var metadata: MetadataTypeUnderTest! @@ -78,7 +78,7 @@ class ObjectWithObjectMetadataTests: XCTestCase { func createPersistables() { item = TypeUnderTest(id: "beatle-1", name: "John") - metadata = Date() + metadata = NSDate() items = [ item, TypeUnderTest(id: "beatle-2", name: "Paul"), @@ -86,7 +86,7 @@ class ObjectWithObjectMetadataTests: XCTestCase { TypeUnderTest(id: "beatle-4", name: "Ringo") ] metadatas = [metadata] - items.suffix(from: 1).forEach { _ in metadatas.append(Date()) } + items.suffix(from: 1).forEach { _ in metadatas.append(NSDate()) } } func configureForReadingSingle() { @@ -105,7 +105,7 @@ class ObjectWithObjectMetadataTests: XCTestCase { XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? Date, metadata) + XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSDate, metadata) } func checkTransactionDidWriteItems(_ result: [YapItem]) { @@ -688,7 +688,7 @@ class Persistable_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataT XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? Date, metadata) + XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSDate, metadata) XCTAssertTrue(connection.didWrite) } diff --git a/Tests/ReadWriteTests.swift b/Tests/ReadWriteTests.swift index c43d3e1..71f048c 100644 --- a/Tests/ReadWriteTests.swift +++ b/Tests/ReadWriteTests.swift @@ -10,12 +10,12 @@ import YapDatabase class ReadWriteBaseTests: XCTestCase { var item: Employee! - var metadata: Date! + var metadata: NSDate! var index: YapDB.Index! var key: String! var items: [Employee]! - var metadatas: [Date?]! + var metadatas: [NSDate?]! var indexes: [YapDB.Index]! var keys: [String]! @@ -43,7 +43,7 @@ class ReadWriteBaseTests: XCTestCase { func createPersistables() { item = Employee(id: "beatle-1", name: "John") - metadata = Date() + metadata = NSDate() items = [ item, Employee(id: "beatle-2", name: "Paul"), @@ -52,14 +52,14 @@ class ReadWriteBaseTests: XCTestCase { ] metadatas = [ metadata, - Date(), - Date(), - Date() + NSDate(), + NSDate(), + NSDate() ] } func writeItemsToDatabase(_ db: YapDatabase) { - db.makeNewConnection().writeWithMetadata(items.yapItems(with: metadatas)) + _ = db.makeNewConnection().writeWithMetadata(items.yapItems(with: metadatas)) } } From a60a509895f021328b76f656dae794a5b209ebf5 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 01:09:24 -0800 Subject: [PATCH 30/54] renames suggested by Xcode --- Tests/YapDatabaseExtensionsTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/YapDatabaseExtensionsTests.swift b/Tests/YapDatabaseExtensionsTests.swift index 8129640..93d3b02 100644 --- a/Tests/YapDatabaseExtensionsTests.swift +++ b/Tests/YapDatabaseExtensionsTests.swift @@ -111,7 +111,7 @@ class YapDatabaseReadWriteTransactionTests: ReadWriteBaseTests { func test__write_at_index_with_metadata() { let db = YapDB.testDatabase() - db.makeNewConnection().readWriteWithBlock { transaction in + db.makeNewConnection().readWrite { transaction in transaction.writeAtIndex(self.index, object: self.item, metadata: self.metadata) } let written: YapItem? = Employee.read(db).withMetadataAtIndex(index) From bfda3f085169f6afd8c0b58eb023cdc35c3d63e1 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 01:21:17 -0800 Subject: [PATCH 31/54] remove Reachability framework from Copy Carthage Frameworks input file list --- YapDatabaseExtensions.xcodeproj/project.pbxproj | 1 - 1 file changed, 1 deletion(-) diff --git a/YapDatabaseExtensions.xcodeproj/project.pbxproj b/YapDatabaseExtensions.xcodeproj/project.pbxproj index 5c997d2..dd69886 100644 --- a/YapDatabaseExtensions.xcodeproj/project.pbxproj +++ b/YapDatabaseExtensions.xcodeproj/project.pbxproj @@ -323,7 +323,6 @@ ValueCoding, YapDatabase, CocoaLumberjack, - Reachability, ); name = "Copy Carthage Frameworks"; outputPaths = ( From 418bb18d800f83375b249e99de8581b46aa0b3fc Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 01:21:33 -0800 Subject: [PATCH 32/54] change the bundle identifiers to com.roepcke.* --- Supporting Files/YapDatabaseExtensions.xcconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Supporting Files/YapDatabaseExtensions.xcconfig b/Supporting Files/YapDatabaseExtensions.xcconfig index bcbbfc1..1287d63 100644 --- a/Supporting Files/YapDatabaseExtensions.xcconfig +++ b/Supporting Files/YapDatabaseExtensions.xcconfig @@ -11,8 +11,8 @@ INFOPLIST_FILE_framework = $(SRCROOT)/Supporting Files/Info.plist INFOPLIST_FILE_xctest = $(SRCROOT)/Tests/Info.plist INFOPLIST_FILE = $(INFOPLIST_FILE_$(WRAPPER_EXTENSION)) -PRODUCT_BUNDLE_IDENTIFIER_framework = me.danthorpe.YapDatabaseExtensions -PRODUCT_BUNDLE_IDENTIFIER_xctest = me.danthorpe.YapDatabaseExtensionsTests +PRODUCT_BUNDLE_IDENTIFIER_framework = com.roepcke.YapDatabaseExtensions +PRODUCT_BUNDLE_IDENTIFIER_xctest = com.roepcke.YapDatabaseExtensionsTests PRODUCT_BUNDLE_IDENTIFIER = $(PRODUCT_BUNDLE_IDENTIFIER_$(WRAPPER_EXTENSION)) PRODUCT_NAME_framework = YapDatabaseExtensions From 082cd844d41abad6568c726348f336fbb75ce075 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 01:23:49 -0800 Subject: [PATCH 33/54] update versions --- Supporting Files/Version.xcconfig | 2 +- Supporting Files/YapDatabaseExtensions.xcconfig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Supporting Files/Version.xcconfig b/Supporting Files/Version.xcconfig index cd3083e..bf8fe70 100644 --- a/Supporting Files/Version.xcconfig +++ b/Supporting Files/Version.xcconfig @@ -1 +1 @@ -YAP_DATABASE_EXTENSIONS_VERSION = 2.6.0 +YAP_DATABASE_EXTENSIONS_VERSION = 3.0.0 diff --git a/Supporting Files/YapDatabaseExtensions.xcconfig b/Supporting Files/YapDatabaseExtensions.xcconfig index 1287d63..3c1ebd9 100644 --- a/Supporting Files/YapDatabaseExtensions.xcconfig +++ b/Supporting Files/YapDatabaseExtensions.xcconfig @@ -23,7 +23,7 @@ APPLICATION_EXTENSION_API_ONLY_framework = YES APPLICATION_EXTENSION_API_ONLY_xctest = NO APPLICATION_EXTENSION_API_ONLY = $(APPLICATION_EXTENSION_API_ONLY_$(WRAPPER_EXTENSION)) -SWIFT_VERSION = 2.3 +SWIFT_VERSION = 3.0 // Build Settings SUPPORTED_PLATFORMS = macosx iphoneos appletvos watchos appletvsimulator iphonesimulator watchsimulator From d2c5282f09d697233e6b52ff089e6a05ee004cc5 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 01:24:12 -0800 Subject: [PATCH 34/54] fix build warnings about unused return values --- Tests/YapDatabaseExtensionsTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/YapDatabaseExtensionsTests.swift b/Tests/YapDatabaseExtensionsTests.swift index 93d3b02..9feba7d 100644 --- a/Tests/YapDatabaseExtensionsTests.swift +++ b/Tests/YapDatabaseExtensionsTests.swift @@ -123,7 +123,7 @@ class YapDatabaseReadWriteTransactionTests: ReadWriteBaseTests { func test__remove_at_indexes() { let db = YapDB.testDatabase() - db.makeNewConnection().write(items) + _ = db.makeNewConnection().write(items) XCTAssertNotNil(Employee.read(db).atIndex(index)) db.makeNewConnection().readWrite { transaction in @@ -149,7 +149,7 @@ class YapDatabaseConnectionTests: ReadWriteBaseTests { let db = YapDB.testDatabase() let expectation = self.expectation(description: "Test: \(#function)") - db.makeNewConnection().write(item) + _ = db.makeNewConnection().write(item) XCTAssertNotNil(Employee.read(db).atIndex(index)) var received: Employee? = .none From 480f25fa8a1a92b582cbef75e2571b109aea26e8 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 01:26:18 -0800 Subject: [PATCH 35/54] update YapDatabase version in the podspec --- YapDatabaseExtensions.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/YapDatabaseExtensions.podspec b/YapDatabaseExtensions.podspec index 46c79fd..944ea54 100644 --- a/YapDatabaseExtensions.podspec +++ b/YapDatabaseExtensions.podspec @@ -23,7 +23,7 @@ Pod::Spec.new do |s| s.osx.deployment_target = '10.11' s.dependency 'ValueCoding', '~> 2.1.0' - s.dependency 'YapDatabase', '2.9.2' + s.dependency 'YapDatabase', '2.9.3' s.subspec 'Core' do |ss| ss.source_files = [ From c84c6cada3f9d9423e4d63f8930d5579a027cd38 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 01:26:27 -0800 Subject: [PATCH 36/54] update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db04f93..dfdd7d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 3.0.0 +1. Separated Metadata from Objects +2. Updated for Swift 3.0 + # 2.6.0 Updated for Swift 2.3 - sorry it's taken so long! From 38934f8e5203bf3352f7d0604d7172481a818d84 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 01:34:46 -0800 Subject: [PATCH 37/54] rename podspec --- YapDatabaseExtensions.podspec => RCSYapDatabaseExtensions.podspec | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename YapDatabaseExtensions.podspec => RCSYapDatabaseExtensions.podspec (100%) diff --git a/YapDatabaseExtensions.podspec b/RCSYapDatabaseExtensions.podspec similarity index 100% rename from YapDatabaseExtensions.podspec rename to RCSYapDatabaseExtensions.podspec From defb99ff9a8f9524b4174d0b6f41662fd32488cd Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 01:57:30 -0800 Subject: [PATCH 38/54] downgrade YapDatabase in the podspec, the 2.9.3 pod release is malformed --- RCSYapDatabaseExtensions.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RCSYapDatabaseExtensions.podspec b/RCSYapDatabaseExtensions.podspec index 944ea54..46c79fd 100644 --- a/RCSYapDatabaseExtensions.podspec +++ b/RCSYapDatabaseExtensions.podspec @@ -23,7 +23,7 @@ Pod::Spec.new do |s| s.osx.deployment_target = '10.11' s.dependency 'ValueCoding', '~> 2.1.0' - s.dependency 'YapDatabase', '2.9.3' + s.dependency 'YapDatabase', '2.9.2' s.subspec 'Core' do |ss| ss.source_files = [ From 9997a4dcc4e1d55e9d951bbd24e4394ed1c75e98 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 02:01:05 -0800 Subject: [PATCH 39/54] fix the subspecs --- RCSYapDatabaseExtensions.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RCSYapDatabaseExtensions.podspec b/RCSYapDatabaseExtensions.podspec index 46c79fd..013359a 100644 --- a/RCSYapDatabaseExtensions.podspec +++ b/RCSYapDatabaseExtensions.podspec @@ -33,12 +33,12 @@ Pod::Spec.new do |s| end s.subspec 'Functional' do |ss| - ss.dependency 'YapDatabaseExtensions/Core' + ss.dependency 'RCSYapDatabaseExtensions/Core' ss.source_files = 'Sources/Functional_*.swift' end s.subspec 'Persitable' do |ss| - ss.dependency 'YapDatabaseExtensions/Functional' + ss.dependency 'RCSYapDatabaseExtensions/Functional' ss.source_files = [ 'Sources/Read.swift', 'Sources/Persistable_*.swift' From 703edcf9657758268507972d1de0754ee85da970 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 29 Dec 2016 02:16:27 -0800 Subject: [PATCH 40/54] import YapDatabase in YapDB.swift --- Sources/YapDB.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/YapDB.swift b/Sources/YapDB.swift index 4cdfee7..f626b02 100644 --- a/Sources/YapDB.swift +++ b/Sources/YapDB.swift @@ -2,6 +2,12 @@ // Created by Daniel Thorpe on 22/04/2015. // +import YapDatabase +import YapDatabase.YapDatabaseView +import YapDatabase.YapDatabaseFilteredView +import YapDatabase.YapDatabaseFullTextSearch +import YapDatabase.YapDatabaseSecondaryIndex + protocol YapDatabaseViewProducer { func createDatabaseView() -> YapDatabaseView } From f7f321d29a2fed32a3484098f5913c3f9e63227d Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Fri, 30 Dec 2016 16:40:54 -0800 Subject: [PATCH 41/54] =?UTF-8?q?don=E2=80=99t=20use=20flatMap=20when=20re?= =?UTF-8?q?ading?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Curried_ObjectWithNoMetadata.swift | 4 +-- .../Curried_ObjectWithObjectMetadata.swift | 4 +-- Sources/Curried_ObjectWithValueMetadata.swift | 4 +-- Sources/Curried_ValueWithNoMetadata.swift | 4 +-- Sources/Curried_ValueWithObjectMetadata.swift | 4 +-- Sources/Curried_ValueWithValueMetadata.swift | 4 +-- .../Functional_AnyWithObjectMetadata.swift | 6 ++-- Sources/Functional_AnyWithValueMetadata.swift | 6 ++-- Sources/Functional_ObjectWithNoMetadata.swift | 14 +++++----- .../Functional_ObjectWithObjectMetadata.swift | 15 +++++----- .../Functional_ObjectWithValueMetadata.swift | 15 +++++----- .../Functional_ValueWIthObjectMetadata.swift | 15 +++++----- .../Functional_ValueWIthValueMetadata.swift | 15 +++++----- Sources/Functional_ValueWithNoMetadata.swift | 14 +++++----- .../Persistable_AnyWithObjectMetadata.swift | 6 ++-- .../Persistable_AnyWithValueMetadata.swift | 6 ++-- .../Persistable_ObjectWithNoMetadata.swift | 26 ++++++++++------- ...Persistable_ObjectWithObjectMetadata.swift | 28 +++++++++++-------- .../Persistable_ObjectWithValueMetadata.swift | 28 +++++++++++-------- Sources/Persistable_ValueWithNoMetadata.swift | 26 ++++++++++------- .../Persistable_ValueWithObjectMetadata.swift | 28 +++++++++++-------- .../Persistable_ValueWithValueMetadata.swift | 28 +++++++++++-------- Tests/ObjectWithNoMetadataTests.swift | 6 ++-- Tests/ObjectWithObjectMetadataTests.swift | 6 ++-- Tests/ObjectWithValueMetadataTests.swift | 6 ++-- Tests/ValueWithNoMetadataTests.swift | 6 ++-- Tests/ValueWithObjectMetadataTests.swift | 12 ++++---- Tests/ValueWithValueMetadataTests.swift | 12 ++++---- 28 files changed, 190 insertions(+), 158 deletions(-) diff --git a/Sources/Curried_ObjectWithNoMetadata.swift b/Sources/Curried_ObjectWithNoMetadata.swift index fdd3454..6429cb5 100644 --- a/Sources/Curried_ObjectWithNoMetadata.swift +++ b/Sources/Curried_ObjectWithNoMetadata.swift @@ -35,7 +35,7 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readAtIndexes< - Indexes, ReadTransaction>(_ indexes: Indexes) -> (ReadTransaction) -> [Self] where + Indexes, ReadTransaction>(_ indexes: Indexes) -> (ReadTransaction) -> [Self?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, ReadTransaction: ReadTransactionType { @@ -63,7 +63,7 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readByKeys< - Keys, ReadTransaction>(_ keys: Keys) -> (ReadTransaction) -> [Self] where + Keys, ReadTransaction>(_ keys: Keys) -> (ReadTransaction) -> [Self?] where Keys: Sequence, Keys.Iterator.Element == String, ReadTransaction: ReadTransactionType { diff --git a/Sources/Curried_ObjectWithObjectMetadata.swift b/Sources/Curried_ObjectWithObjectMetadata.swift index 3fe8990..9ea47fe 100644 --- a/Sources/Curried_ObjectWithObjectMetadata.swift +++ b/Sources/Curried_ObjectWithObjectMetadata.swift @@ -36,7 +36,7 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataAtIndexes< - Indexes, ReadTransaction, Metadata>(_ indexes: Indexes) -> (ReadTransaction) -> [YapItem] where + Indexes, ReadTransaction, Metadata>(_ indexes: Indexes) -> (ReadTransaction) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, ReadTransaction: ReadTransactionType, @@ -66,7 +66,7 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataByKeys< - Keys, ReadTransaction, Metadata>(_ keys: Keys) -> (ReadTransaction) -> [YapItem] where + Keys, ReadTransaction, Metadata>(_ keys: Keys) -> (ReadTransaction) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, ReadTransaction: ReadTransactionType, diff --git a/Sources/Curried_ObjectWithValueMetadata.swift b/Sources/Curried_ObjectWithValueMetadata.swift index a726ea5..be14cda 100644 --- a/Sources/Curried_ObjectWithValueMetadata.swift +++ b/Sources/Curried_ObjectWithValueMetadata.swift @@ -38,7 +38,7 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataAtIndexes< - Indexes, ReadTransaction, Metadata>(_ indexes: Indexes) -> (ReadTransaction) -> [YapItem] where + Indexes, ReadTransaction, Metadata>(_ indexes: Indexes) -> (ReadTransaction) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, ReadTransaction: ReadTransactionType, @@ -72,7 +72,7 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataByKeys< - Keys, ReadTransaction, Metadata>(_ keys: Keys) -> (ReadTransaction) -> [YapItem] where + Keys, ReadTransaction, Metadata>(_ keys: Keys) -> (ReadTransaction) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, ReadTransaction: ReadTransactionType, diff --git a/Sources/Curried_ValueWithNoMetadata.swift b/Sources/Curried_ValueWithNoMetadata.swift index 01ea119..cf5eab8 100644 --- a/Sources/Curried_ValueWithNoMetadata.swift +++ b/Sources/Curried_ValueWithNoMetadata.swift @@ -37,7 +37,7 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readAtIndexes< - Indexes, ReadTransaction>(_ indexes: Indexes) -> (ReadTransaction) -> [Self] where + Indexes, ReadTransaction>(_ indexes: Indexes) -> (ReadTransaction) -> [Self?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, ReadTransaction: ReadTransactionType { @@ -65,7 +65,7 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readByKeys< - Keys, ReadTransaction>(_ keys: Keys) -> (ReadTransaction) -> [Self] where + Keys, ReadTransaction>(_ keys: Keys) -> (ReadTransaction) -> [Self?] where Keys: Sequence, Keys.Iterator.Element == String, ReadTransaction: ReadTransactionType { diff --git a/Sources/Curried_ValueWithObjectMetadata.swift b/Sources/Curried_ValueWithObjectMetadata.swift index 8b31bc0..26ce801 100644 --- a/Sources/Curried_ValueWithObjectMetadata.swift +++ b/Sources/Curried_ValueWithObjectMetadata.swift @@ -38,7 +38,7 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataAtIndexes< - Indexes, ReadTransaction, Metadata>(_ indexes: Indexes) -> (ReadTransaction) -> [YapItem] where + Indexes, ReadTransaction, Metadata>(_ indexes: Indexes) -> (ReadTransaction) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, ReadTransaction: ReadTransactionType, @@ -68,7 +68,7 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataByKeys< - Keys, ReadTransaction, Metadata>(_ keys: Keys) -> (ReadTransaction) -> [YapItem] where + Keys, ReadTransaction, Metadata>(_ keys: Keys) -> (ReadTransaction) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, ReadTransaction: ReadTransactionType, diff --git a/Sources/Curried_ValueWithValueMetadata.swift b/Sources/Curried_ValueWithValueMetadata.swift index 07ddb55..8043070 100644 --- a/Sources/Curried_ValueWithValueMetadata.swift +++ b/Sources/Curried_ValueWithValueMetadata.swift @@ -40,7 +40,7 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataAtIndexes< - Indexes, ReadTransaction, Metadata>(_ indexes: Indexes) -> (ReadTransaction) -> [YapItem] where + Indexes, ReadTransaction, Metadata>(_ indexes: Indexes) -> (ReadTransaction) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, ReadTransaction: ReadTransactionType, @@ -74,7 +74,7 @@ extension Persistable where - returns: a (ReadTransaction) -> [Self] closure. */ public static func readWithMetadataByKeys< - Keys, ReadTransaction, Metadata>(_ keys: Keys) -> (ReadTransaction) -> [YapItem] where + Keys, ReadTransaction, Metadata>(_ keys: Keys) -> (ReadTransaction) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, ReadTransaction: ReadTransactionType, diff --git a/Sources/Functional_AnyWithObjectMetadata.swift b/Sources/Functional_AnyWithObjectMetadata.swift index a68609d..367ef22 100644 --- a/Sources/Functional_AnyWithObjectMetadata.swift +++ b/Sources/Functional_AnyWithObjectMetadata.swift @@ -32,11 +32,11 @@ extension ReadTransactionType { - returns: an array of `MetadataType` */ public func readMetadataAtIndexes< - Indexes, MetadataType>(_ indexes: Indexes) -> [MetadataType] where + Indexes, MetadataType>(_ indexes: Indexes) -> [MetadataType?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, MetadataType: NSCoding { - return indexes.flatMap(readMetadataAtIndex) + return indexes.map(readMetadataAtIndex) } } @@ -60,7 +60,7 @@ extension ConnectionType { - returns: an array of `MetadataType` */ public func readMetadataAtIndexes< - Indexes, MetadataType>(_ indexes: Indexes) -> [MetadataType] where + Indexes, MetadataType>(_ indexes: Indexes) -> [MetadataType?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, MetadataType: NSCoding { diff --git a/Sources/Functional_AnyWithValueMetadata.swift b/Sources/Functional_AnyWithValueMetadata.swift index 0f4890f..fe210ef 100644 --- a/Sources/Functional_AnyWithValueMetadata.swift +++ b/Sources/Functional_AnyWithValueMetadata.swift @@ -35,13 +35,13 @@ extension ReadTransactionType { - returns: an array of `MetadataType` */ public func readMetadataAtIndexes< - Indexes, MetadataType>(_ indexes: Indexes) -> [MetadataType] where + Indexes, MetadataType>(_ indexes: Indexes) -> [MetadataType?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, MetadataType: ValueCoding, MetadataType.Coder: NSCoding, MetadataType.Coder.Value == MetadataType { - return indexes.flatMap(readMetadataAtIndex) + return indexes.map(readMetadataAtIndex) } } @@ -68,7 +68,7 @@ extension ConnectionType { - returns: an array of `MetadataType` */ public func readMetadataAtIndexes< - Indexes, MetadataType>(_ indexes: Indexes) -> [MetadataType] where + Indexes, MetadataType>(_ indexes: Indexes) -> [MetadataType?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, MetadataType: ValueCoding, diff --git a/Sources/Functional_ObjectWithNoMetadata.swift b/Sources/Functional_ObjectWithNoMetadata.swift index 251bab3..f67317a 100644 --- a/Sources/Functional_ObjectWithNoMetadata.swift +++ b/Sources/Functional_ObjectWithNoMetadata.swift @@ -34,12 +34,12 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, Object>(_ indexes: Indexes) -> [Object] where + Indexes, Object>(_ indexes: Indexes) -> [Object?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Object: Persistable, Object: NSCoding { - return indexes.flatMap(readAtIndex) + return indexes.map(readAtIndex) } /** @@ -62,7 +62,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, Object>(_ keys: Keys) -> [Object] where + Keys, Object>(_ keys: Keys) -> [Object?] where Keys: Sequence, Keys.Iterator.Element == String, Object: Persistable, @@ -76,7 +76,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAll< - Object>() -> [Object] where + Object>() -> [Object?] where Object: Persistable, Object: NSCoding { return readByKeys(keysInCollection(Object.collection)) @@ -105,7 +105,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, Object>(_ indexes: Indexes) -> [Object] where + Indexes, Object>(_ indexes: Indexes) -> [Object?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Object: Persistable, @@ -133,7 +133,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, Object>(_ keys: Keys) -> [Object] where + Keys, Object>(_ keys: Keys) -> [Object?] where Keys: Sequence, Keys.Iterator.Element == String, Object: Persistable, @@ -147,7 +147,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAll< - Object>() -> [Object] where + Object>() -> [Object?] where Object: Persistable, Object: NSCoding { return read { $0.readAll() } diff --git a/Sources/Functional_ObjectWithObjectMetadata.swift b/Sources/Functional_ObjectWithObjectMetadata.swift index d581974..70e2d60 100644 --- a/Sources/Functional_ObjectWithObjectMetadata.swift +++ b/Sources/Functional_ObjectWithObjectMetadata.swift @@ -37,14 +37,13 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Object, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes, Object, Metadata>(_ indexes: Indexes) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Object: Persistable, Object: NSCoding, Metadata: NSCoding { - // FIXME: using flatMap means the output length need not match the input length - return indexes.flatMap(readWithMetadataAtIndex) + return indexes.map(readWithMetadataAtIndex) } /** @@ -68,7 +67,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Object, Metadata>(_ keys: Keys) -> [YapItem] where + Keys, Object, Metadata>(_ keys: Keys) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, Object: Persistable, @@ -83,7 +82,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Object, Metadata>() -> [YapItem] where + Object, Metadata>() -> [YapItem?] where Object: Persistable, Object: NSCoding, Metadata: NSCoding { @@ -114,7 +113,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Object, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes, Object, Metadata>(_ indexes: Indexes) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Object: Persistable, @@ -144,7 +143,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Object, Metadata>(_ keys: Keys) -> [YapItem] where + Keys, Object, Metadata>(_ keys: Keys) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, Object: Persistable, @@ -159,7 +158,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Object, Metadata>() -> [YapItem] where + Object, Metadata>() -> [YapItem?] where Object: Persistable, Object: NSCoding, Metadata: NSCoding { diff --git a/Sources/Functional_ObjectWithValueMetadata.swift b/Sources/Functional_ObjectWithValueMetadata.swift index 7bb30f0..8c9906c 100644 --- a/Sources/Functional_ObjectWithValueMetadata.swift +++ b/Sources/Functional_ObjectWithValueMetadata.swift @@ -39,7 +39,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Object, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes, Object, Metadata>(_ indexes: Indexes) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Object: Persistable, @@ -47,8 +47,7 @@ extension ReadTransactionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { - // FIXME: using flatMap means the output length need not match the input length - return indexes.flatMap(readWithMetadataAtIndex) + return indexes.map(readWithMetadataAtIndex) } /** @@ -74,7 +73,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Object, Metadata>(_ keys: Keys) -> [YapItem] where + Keys, Object, Metadata>(_ keys: Keys) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, Object: Persistable, @@ -91,7 +90,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Object, Metadata>() -> [YapItem] where + Object, Metadata>() -> [YapItem?] where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, @@ -126,7 +125,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Object, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes, Object, Metadata>(_ indexes: Indexes) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Object: Persistable, @@ -160,7 +159,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Object, Metadata>(_ keys: Keys) -> [YapItem] where + Keys, Object, Metadata>(_ keys: Keys) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, Object: Persistable, @@ -177,7 +176,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Object, Metadata>() -> [YapItem] where + Object, Metadata>() -> [YapItem?] where Object: Persistable, Object: NSCoding, Metadata: ValueCoding, diff --git a/Sources/Functional_ValueWIthObjectMetadata.swift b/Sources/Functional_ValueWIthObjectMetadata.swift index c19151e..9e416fe 100644 --- a/Sources/Functional_ValueWIthObjectMetadata.swift +++ b/Sources/Functional_ValueWIthObjectMetadata.swift @@ -39,7 +39,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Value, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes, Value, Metadata>(_ indexes: Indexes) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Value: Persistable, @@ -47,8 +47,7 @@ extension ReadTransactionType { Value.Coder: NSCoding, Value.Coder.Value == Value, Metadata: NSCoding { - // FIXME: using flatMap means the output length need not match the input length - return indexes.flatMap(readWithMetadataAtIndex) + return indexes.map(readWithMetadataAtIndex) } /** @@ -74,7 +73,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Value, Metadata>(_ keys: Keys) -> [YapItem] where + Keys, Value, Metadata>(_ keys: Keys) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, Value: Persistable, @@ -91,7 +90,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Value, Metadata>() -> [YapItem] where + Value, Metadata>() -> [YapItem?] where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, @@ -126,7 +125,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Value, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes, Value, Metadata>(_ indexes: Indexes) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Value: Persistable, @@ -160,7 +159,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Value, Metadata>(_ keys: Keys) -> [YapItem] where + Keys, Value, Metadata>(_ keys: Keys) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, Value: Persistable, @@ -177,7 +176,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Value, Metadata>() -> [YapItem] where + Value, Metadata>() -> [YapItem?] where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, diff --git a/Sources/Functional_ValueWIthValueMetadata.swift b/Sources/Functional_ValueWIthValueMetadata.swift index 0aef12c..2147f6f 100644 --- a/Sources/Functional_ValueWIthValueMetadata.swift +++ b/Sources/Functional_ValueWIthValueMetadata.swift @@ -41,7 +41,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Value, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes, Value, Metadata>(_ indexes: Indexes) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Value: Persistable, @@ -51,8 +51,7 @@ extension ReadTransactionType { Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { - // FIXME: using flatMap means the output length need not match the input length - return indexes.flatMap(readWithMetadataAtIndex) + return indexes.map(readWithMetadataAtIndex) } /** @@ -80,7 +79,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Value, Metadata>(_ keys: Keys) -> [YapItem] where + Keys, Value, Metadata>(_ keys: Keys) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, Value: Persistable, @@ -99,7 +98,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Value, Metadata>() -> [YapItem] where + Value, Metadata>() -> [YapItem?] where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, @@ -138,7 +137,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAtIndexes< - Indexes, Value, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes, Value, Metadata>(_ indexes: Indexes) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Value: Persistable, @@ -176,7 +175,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataByKeys< - Keys, Value, Metadata>(_ keys: Keys) -> [YapItem] where + Keys, Value, Metadata>(_ keys: Keys) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, Value: Persistable, @@ -195,7 +194,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readWithMetadataAll< - Value, Metadata>() -> [YapItem] where + Value, Metadata>() -> [YapItem?] where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, diff --git a/Sources/Functional_ValueWithNoMetadata.swift b/Sources/Functional_ValueWithNoMetadata.swift index 813c0fb..156a4b9 100644 --- a/Sources/Functional_ValueWithNoMetadata.swift +++ b/Sources/Functional_ValueWithNoMetadata.swift @@ -36,14 +36,14 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, Value>(_ indexes: Indexes) -> [Value] where + Indexes, Value>(_ indexes: Indexes) -> [Value?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, Value.Coder.Value == Value { - return indexes.flatMap(readAtIndex) + return indexes.map(readAtIndex) } /** @@ -68,7 +68,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, Value>(_ keys: Keys) -> [Value] where + Keys, Value>(_ keys: Keys) -> [Value?] where Keys: Sequence, Keys.Iterator.Element == String, Value: Persistable, @@ -84,7 +84,7 @@ extension ReadTransactionType { - returns: an array of `ItemType` */ public func readAll< - Value>() -> [Value] where + Value>() -> [Value?] where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, @@ -117,7 +117,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAtIndexes< - Indexes, Value>(_ indexes: Indexes) -> [Value] where + Indexes, Value>(_ indexes: Indexes) -> [Value?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Value: Persistable, @@ -149,7 +149,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readByKeys< - Keys, Value>(_ keys: Keys) -> [Value] where + Keys, Value>(_ keys: Keys) -> [Value?] where Keys: Sequence, Keys.Iterator.Element == String, Value: Persistable, @@ -165,7 +165,7 @@ extension ConnectionType { - returns: an array of `ItemType` */ public func readAll< - Value>() -> [Value] where + Value>() -> [Value?] where Value: Persistable, Value: ValueCoding, Value.Coder: NSCoding, diff --git a/Sources/Persistable_AnyWithObjectMetadata.swift b/Sources/Persistable_AnyWithObjectMetadata.swift index a216d76..ed3e226 100644 --- a/Sources/Persistable_AnyWithObjectMetadata.swift +++ b/Sources/Persistable_AnyWithObjectMetadata.swift @@ -27,11 +27,11 @@ extension Readable where } func metadataAtIndexesInTransaction< - Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [Metadata] where + Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [Metadata?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Metadata: NSCoding { - return { indexes.flatMap(self.metadataInTransactionAtIndex($0)) } + return { indexes.map(self.metadataInTransactionAtIndex($0)) } } /** @@ -53,7 +53,7 @@ extension Readable where - returns: an array of `Metadata` */ public func metadataAtIndexes< - Indexes, Metadata>(_ indexes: Indexes) -> [Metadata] where + Indexes, Metadata>(_ indexes: Indexes) -> [Metadata?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Metadata: NSCoding { diff --git a/Sources/Persistable_AnyWithValueMetadata.swift b/Sources/Persistable_AnyWithValueMetadata.swift index 0fd6211..ceeb1a1 100644 --- a/Sources/Persistable_AnyWithValueMetadata.swift +++ b/Sources/Persistable_AnyWithValueMetadata.swift @@ -39,13 +39,13 @@ extension Readable where } func metadataAtIndexesInTransaction< - Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [Metadata] where + Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [Metadata?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { - return { indexes.flatMap(self.metadataInTransactionAtIndex($0)) } + return { indexes.map(self.metadataInTransactionAtIndex($0)) } } /** @@ -69,7 +69,7 @@ extension Readable where - returns: an array of `Metadata` */ public func metadataAtIndexes< - Indexes, Metadata>(_ indexes: Indexes) -> [Metadata] where + Indexes, Metadata>(_ indexes: Indexes) -> [Metadata?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Metadata: ValueCoding, diff --git a/Sources/Persistable_ObjectWithNoMetadata.swift b/Sources/Persistable_ObjectWithNoMetadata.swift index 805d3ca..52072d6 100644 --- a/Sources/Persistable_ObjectWithNoMetadata.swift +++ b/Sources/Persistable_ObjectWithNoMetadata.swift @@ -121,11 +121,11 @@ extension Readable where } func atIndexesInTransaction< - Indexes>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [ItemType] where + Indexes>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [ItemType?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index { let atIndex = inTransactionAtIndex - return { indexes.flatMap(atIndex($0)) } + return { indexes.map(atIndex($0)) } } func inTransaction(_ transaction: Database.Connection.ReadTransaction, byKey key: String) -> ItemType? { @@ -140,11 +140,11 @@ extension Readable where return { self.inTransaction($0, byKey: key) } } - func byKeysInTransaction(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [ItemType] { + func byKeysInTransaction(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [ItemType?] { let byKey = inTransactionByKey return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(byKey(transaction)) + return keys.map(byKey(transaction)) } } @@ -165,7 +165,7 @@ extension Readable where - returns: an array of `ItemType` */ public func atIndexes< - Indexes>(_ indexes: Indexes) -> [ItemType] where + Indexes>(_ indexes: Indexes) -> [ItemType?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index { return sync(atIndexesInTransaction(indexes)) @@ -188,7 +188,7 @@ extension Readable where - returns: an array of `ItemType` */ public func byKeys< - Keys>(_ keys: Keys) -> [ItemType] where + Keys>(_ keys: Keys) -> [ItemType?] where Keys: Sequence, Keys.Iterator.Element == String { return sync(byKeysInTransaction(Array(keys))) @@ -199,7 +199,7 @@ extension Readable where - returns: an array of `ItemType` */ - public func all() -> [ItemType] { + public func all() -> [ItemType?] { return sync(byKeysInTransaction()) } @@ -212,9 +212,15 @@ extension Readable where public func filterExisting(_ keys: [String]) -> (existing: [ItemType], missing: [String]) { let existingInTransaction = byKeysInTransaction(keys) return sync { transaction -> ([ItemType], [String]) in - let existing = existingInTransaction(transaction) - let existingKeys = existing.map(keyForPersistable) - let missingKeys = keys.filter { !existingKeys.contains($0) } + var missingKeys = [String]() + let maybeExisting = existingInTransaction(transaction) + let existing = zip(keys, maybeExisting).flatMap { zipped -> ItemType? in + guard let item = zipped.1 else { + missingKeys.append(zipped.0) + return nil + } + return item + } return (existing, missingKeys) } } diff --git a/Sources/Persistable_ObjectWithObjectMetadata.swift b/Sources/Persistable_ObjectWithObjectMetadata.swift index 114b6ce..4f33c88 100644 --- a/Sources/Persistable_ObjectWithObjectMetadata.swift +++ b/Sources/Persistable_ObjectWithObjectMetadata.swift @@ -164,11 +164,11 @@ extension Readable where } func withMetadataAtIndexesInTransaction< - Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [YapItem] where + Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Metadata: NSCoding { - return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } + return { indexes.map(self.withMetadataInTransactionAtIndex($0)) } } func withMetadataInTransaction(_ transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? { @@ -183,10 +183,10 @@ extension Readable where return { self.withMetadataInTransaction($0, byKey: key) } } - func withMetadataByKeysInTransaction(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [YapItem] { + func withMetadataByKeysInTransaction(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [YapItem?] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) + return keys.map(self.withMetadataInTransactionByKey(transaction)) } } @@ -207,7 +207,7 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataAtIndexes< - Indexes, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes, Metadata>(_ indexes: Indexes) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Metadata: NSCoding { @@ -231,7 +231,7 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataByKeys< - Keys, Metadata>(_ keys: Keys) -> [YapItem] where + Keys, Metadata>(_ keys: Keys) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, Metadata: NSCoding { @@ -243,7 +243,7 @@ extension Readable where - returns: an array of `ItemType` */ - public func withMetadataAll() -> [YapItem] { + public func withMetadataAll() -> [YapItem?] { return sync(withMetadataByKeysInTransaction()) } @@ -254,11 +254,17 @@ extension Readable where - returns: a tuple of type `([ItemType], [String])` */ public func withMetadataFilterExisting(_ keys: [String]) -> (existing: [YapItem], missing: [String]) { - let existingInTransaction: (Database.Connection.ReadTransaction) -> [YapItem] = withMetadataByKeysInTransaction(keys) + let existingInTransaction: (Database.Connection.ReadTransaction) -> [YapItem?] = withMetadataByKeysInTransaction(keys) return sync { transaction -> ([YapItem], [String]) in - let existing = existingInTransaction(transaction) - let existingKeys = existing.map {keyForPersistable($0.value)} - let missingKeys = keys.filter { !existingKeys.contains($0) } + var missingKeys = [String]() + let maybeExisting = existingInTransaction(transaction) + let existing = zip(keys, maybeExisting).flatMap { zipped -> YapItem? in + guard let item = zipped.1 else { + missingKeys.append(zipped.0) + return nil + } + return item + } return (existing, missingKeys) } } diff --git a/Sources/Persistable_ObjectWithValueMetadata.swift b/Sources/Persistable_ObjectWithValueMetadata.swift index 6b7cd35..e71fa2e 100644 --- a/Sources/Persistable_ObjectWithValueMetadata.swift +++ b/Sources/Persistable_ObjectWithValueMetadata.swift @@ -194,13 +194,13 @@ extension Readable where } func withMetadataAtIndexesInTransaction< - Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [YapItem] where + Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { - return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } + return { indexes.map(self.withMetadataInTransactionAtIndex($0)) } } func withMetadataInTransaction< @@ -228,13 +228,13 @@ extension Readable where } func withMetadataByKeysInTransaction< - Metadata>(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [YapItem] where + Metadata>(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [YapItem?] where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) + return keys.map(self.withMetadataInTransactionByKey(transaction)) } } @@ -259,7 +259,7 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataAtIndexes< - Indexes, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes, Metadata>(_ indexes: Indexes) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Metadata: ValueCoding, @@ -289,7 +289,7 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataByKeys< - Keys, Metadata>(_ keys: Keys) -> [YapItem] where + Keys, Metadata>(_ keys: Keys) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, Metadata: ValueCoding, @@ -304,7 +304,7 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataAll< - Metadata>() -> [YapItem] where + Metadata>() -> [YapItem?] where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { @@ -322,11 +322,17 @@ extension Readable where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { - let existingInTransaction: (Database.Connection.ReadTransaction) -> [YapItem] = withMetadataByKeysInTransaction(keys) + let existingInTransaction: (Database.Connection.ReadTransaction) -> [YapItem?] = withMetadataByKeysInTransaction(keys) return sync { transaction -> ([YapItem], [String]) in - let existing = existingInTransaction(transaction) - let existingKeys = existing.map {keyForPersistable($0.value)} - let missingKeys = keys.filter { !existingKeys.contains($0) } + var missingKeys = [String]() + let maybeExisting = existingInTransaction(transaction) + let existing = zip(keys, maybeExisting).flatMap { zipped -> YapItem? in + guard let item = zipped.1 else { + missingKeys.append(zipped.0) + return nil + } + return item + } return (existing, missingKeys) } } diff --git a/Sources/Persistable_ValueWithNoMetadata.swift b/Sources/Persistable_ValueWithNoMetadata.swift index 7988f65..40f8225 100644 --- a/Sources/Persistable_ValueWithNoMetadata.swift +++ b/Sources/Persistable_ValueWithNoMetadata.swift @@ -127,11 +127,11 @@ extension Readable where } func atIndexesInTransaction< - Indexes>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [ItemType] where + Indexes>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [ItemType?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index { let atIndex = inTransactionAtIndex - return { indexes.flatMap(atIndex($0)) } + return { indexes.map(atIndex($0)) } } func inTransaction(_ transaction: Database.Connection.ReadTransaction, byKey key: String) -> ItemType? { @@ -146,11 +146,11 @@ extension Readable where return { self.inTransaction($0, byKey: key) } } - func byKeysInTransaction(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [ItemType] { + func byKeysInTransaction(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [ItemType?] { let byKey = inTransactionByKey return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(byKey(transaction)) + return keys.map(byKey(transaction)) } } @@ -171,7 +171,7 @@ extension Readable where - returns: an array of `ItemType` */ public func atIndexes< - Indexes>(_ indexes: Indexes) -> [ItemType] where + Indexes>(_ indexes: Indexes) -> [ItemType?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index { return sync(atIndexesInTransaction(indexes)) @@ -194,7 +194,7 @@ extension Readable where - returns: an array of `ItemType` */ public func byKeys< - Keys>(_ keys: Keys) -> [ItemType] where + Keys>(_ keys: Keys) -> [ItemType?] where Keys: Sequence, Keys.Iterator.Element == String { return sync(byKeysInTransaction(Array(keys))) @@ -205,7 +205,7 @@ extension Readable where - returns: an array of `ItemType` */ - public func all() -> [ItemType] { + public func all() -> [ItemType?] { return sync(byKeysInTransaction()) } @@ -218,9 +218,15 @@ extension Readable where public func filterExisting(_ keys: [String]) -> (existing: [ItemType], missing: [String]) { let existingInTransaction = byKeysInTransaction(keys) return sync { transaction -> ([ItemType], [String]) in - let existing = existingInTransaction(transaction) - let existingKeys = existing.map(keyForPersistable) - let missingKeys = keys.filter { !existingKeys.contains($0) } + var missingKeys = [String]() + let maybeExisting = existingInTransaction(transaction) + let existing = zip(keys, maybeExisting).flatMap { zipped -> ItemType? in + guard let item = zipped.1 else { + missingKeys.append(zipped.0) + return nil + } + return item + } return (existing, missingKeys) } } diff --git a/Sources/Persistable_ValueWithObjectMetadata.swift b/Sources/Persistable_ValueWithObjectMetadata.swift index 1725c2c..4af8229 100644 --- a/Sources/Persistable_ValueWithObjectMetadata.swift +++ b/Sources/Persistable_ValueWithObjectMetadata.swift @@ -171,11 +171,11 @@ extension Readable where } func withMetadataAtIndexesInTransaction< - Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [YapItem] where + Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Metadata: NSCoding { - return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } + return { indexes.map(self.withMetadataInTransactionAtIndex($0)) } } func withMetadataInTransaction(_ transaction: Database.Connection.ReadTransaction, byKey key: String) -> YapItem? { @@ -190,10 +190,10 @@ extension Readable where return { self.withMetadataInTransaction($0, byKey: key) } } - func withMetadataByKeysInTransaction(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [YapItem] { + func withMetadataByKeysInTransaction(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [YapItem?] { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) + return keys.map(self.withMetadataInTransactionByKey(transaction)) } } @@ -214,7 +214,7 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataAtIndexes< - Indexes, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes, Metadata>(_ indexes: Indexes) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Metadata: NSCoding { @@ -238,7 +238,7 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataByKeys< - Keys, Metadata>(_ keys: Keys) -> [YapItem] where + Keys, Metadata>(_ keys: Keys) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, Metadata: NSCoding { @@ -250,7 +250,7 @@ extension Readable where - returns: an array of `ItemType` */ - public func withMetadataAll() -> [YapItem] { + public func withMetadataAll() -> [YapItem?] { return sync(withMetadataByKeysInTransaction()) } @@ -261,11 +261,17 @@ extension Readable where - returns: a tuple of type `([ItemType], [String])` */ public func withMetadataFilterExisting(_ keys: [String]) -> (existing: [YapItem], missing: [String]) { - let existingInTransaction: (Database.Connection.ReadTransaction) -> [YapItem] = withMetadataByKeysInTransaction(keys) + let existingInTransaction: (Database.Connection.ReadTransaction) -> [YapItem?] = withMetadataByKeysInTransaction(keys) return sync { transaction -> ([YapItem], [String]) in - let existing = existingInTransaction(transaction) - let existingKeys = existing.map {keyForPersistable($0.value)} - let missingKeys = keys.filter { !existingKeys.contains($0) } + var missingKeys = [String]() + let maybeExisting = existingInTransaction(transaction) + let existing = zip(keys, maybeExisting).flatMap { zipped -> YapItem? in + guard let item = zipped.1 else { + missingKeys.append(zipped.0) + return nil + } + return item + } return (existing, missingKeys) } } diff --git a/Sources/Persistable_ValueWithValueMetadata.swift b/Sources/Persistable_ValueWithValueMetadata.swift index 1db038f..4d60aff 100644 --- a/Sources/Persistable_ValueWithValueMetadata.swift +++ b/Sources/Persistable_ValueWithValueMetadata.swift @@ -200,13 +200,13 @@ extension Readable where } func withMetadataAtIndexesInTransaction< - Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [YapItem] where + Indexes, Metadata>(_ indexes: Indexes) -> (Database.Connection.ReadTransaction) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { - return { indexes.flatMap(self.withMetadataInTransactionAtIndex($0)) } + return { indexes.map(self.withMetadataInTransactionAtIndex($0)) } } func withMetadataInTransaction< @@ -234,13 +234,13 @@ extension Readable where } func withMetadataByKeysInTransaction< - Metadata>(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [YapItem] where + Metadata>(_ keys: [String]? = .none) -> (Database.Connection.ReadTransaction) -> [YapItem?] where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { return { transaction in let keys = keys ?? transaction.keysInCollection(ItemType.collection) - return keys.flatMap(self.withMetadataInTransactionByKey(transaction)) + return keys.map(self.withMetadataInTransactionByKey(transaction)) } } @@ -265,7 +265,7 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataAtIndexes< - Indexes, Metadata>(_ indexes: Indexes) -> [YapItem] where + Indexes, Metadata>(_ indexes: Indexes) -> [YapItem?] where Indexes: Sequence, Indexes.Iterator.Element == YapDB.Index, Metadata: ValueCoding, @@ -295,7 +295,7 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataByKeys< - Keys, Metadata>(_ keys: Keys) -> [YapItem] where + Keys, Metadata>(_ keys: Keys) -> [YapItem?] where Keys: Sequence, Keys.Iterator.Element == String, Metadata: ValueCoding, @@ -310,7 +310,7 @@ extension Readable where - returns: an array of `ItemType` */ public func withMetadataAll< - Metadata>() -> [YapItem] where + Metadata>() -> [YapItem?] where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { @@ -328,11 +328,17 @@ extension Readable where Metadata: ValueCoding, Metadata.Coder: NSCoding, Metadata.Coder.Value == Metadata { - let existingInTransaction: (Database.Connection.ReadTransaction) -> [YapItem] = withMetadataByKeysInTransaction(keys) + let existingInTransaction: (Database.Connection.ReadTransaction) -> [YapItem?] = withMetadataByKeysInTransaction(keys) return sync { transaction -> ([YapItem], [String]) in - let existing = existingInTransaction(transaction) - let existingKeys = existing.map {keyForPersistable($0.value)} - let missingKeys = keys.filter { !existingKeys.contains($0) } + var missingKeys = [String]() + let maybeExisting = existingInTransaction(transaction) + let existing = zip(keys, maybeExisting).flatMap { zipped -> YapItem? in + guard let item = zipped.1 else { + missingKeys.append(zipped.0) + return nil + } + return item + } return (existing, missingKeys) } } diff --git a/Tests/ObjectWithNoMetadataTests.swift b/Tests/ObjectWithNoMetadataTests.swift index 5cc55a4..bb22b11 100644 --- a/Tests/ObjectWithNoMetadataTests.swift +++ b/Tests/ObjectWithNoMetadataTests.swift @@ -115,12 +115,12 @@ class ObjectWithNoMetadataTests: XCTestCase { return true } - func checkTransactionDidReadItems(_ result: [TypeUnderTest]) -> Bool { - if result.isEmpty { + func checkTransactionDidReadItems(_ result: [TypeUnderTest?]) -> Bool { + if result.flatMap({$0}).isEmpty { return false } XCTAssertEqual(Set(readTransaction.didReadAtIndexes), Set(indexes)) - XCTAssertEqual(result.count, items.count) + XCTAssertEqual(result.flatMap({$0}).count, items.count) return true } diff --git a/Tests/ObjectWithObjectMetadataTests.swift b/Tests/ObjectWithObjectMetadataTests.swift index dc41b2a..eb3139c 100644 --- a/Tests/ObjectWithObjectMetadataTests.swift +++ b/Tests/ObjectWithObjectMetadataTests.swift @@ -127,12 +127,12 @@ class ObjectWithObjectMetadataTests: XCTestCase { return true } - func checkTransactionDidReadItems(_ result: [YapItem]) -> Bool { - if result.isEmpty { + func checkTransactionDidReadItems(_ result: [YapItem?]) -> Bool { + if result.flatMap({$0}).isEmpty { return false } XCTAssertEqual(Set(readTransaction.didReadAtIndexes), Set(indexes)) - XCTAssertEqual(result.count, items.count) + XCTAssertEqual(result.flatMap({$0}).count, items.count) return true } diff --git a/Tests/ObjectWithValueMetadataTests.swift b/Tests/ObjectWithValueMetadataTests.swift index 1296ebb..339a60f 100644 --- a/Tests/ObjectWithValueMetadataTests.swift +++ b/Tests/ObjectWithValueMetadataTests.swift @@ -131,12 +131,12 @@ class ObjectWithValueMetadataTests: XCTestCase { return true } - func checkTransactionDidReadItems(_ result: [YapItem]) -> Bool { - if result.isEmpty { + func checkTransactionDidReadItems(_ result: [YapItem?]) -> Bool { + if result.flatMap({$0}).isEmpty { return false } XCTAssertEqual(Set(readTransaction.didReadAtIndexes), Set(indexes)) - XCTAssertEqual(result.count, items.count) + XCTAssertEqual(result.flatMap({$0}).count, items.count) return true } diff --git a/Tests/ValueWithNoMetadataTests.swift b/Tests/ValueWithNoMetadataTests.swift index 735bf9f..50e9364 100644 --- a/Tests/ValueWithNoMetadataTests.swift +++ b/Tests/ValueWithNoMetadataTests.swift @@ -117,12 +117,12 @@ class ValueWithNoMetadataTests: XCTestCase { return true } - func checkTransactionDidReadItems(_ result: [TypeUnderTest]) -> Bool { - if result.isEmpty { + func checkTransactionDidReadItems(_ result: [TypeUnderTest?]) -> Bool { + if result.flatMap({$0}).isEmpty { return false } XCTAssertEqual(Set(readTransaction.didReadAtIndexes), Set(indexes)) - XCTAssertEqual(result.count, items.count) + XCTAssertEqual(result.flatMap({$0}).count, items.count) return true } diff --git a/Tests/ValueWithObjectMetadataTests.swift b/Tests/ValueWithObjectMetadataTests.swift index b6a0713..e552ae5 100644 --- a/Tests/ValueWithObjectMetadataTests.swift +++ b/Tests/ValueWithObjectMetadataTests.swift @@ -149,12 +149,12 @@ class ValueWithObjectMetadataTests: XCTestCase { return true } - func checkTransactionDidReadItems(_ result: [YapItem]) -> Bool { - if result.isEmpty { + func checkTransactionDidReadItems(_ result: [YapItem?]) -> Bool { + if result.flatMap({$0}).isEmpty { return false } XCTAssertEqual(Set(readTransaction.didReadAtIndexes), Set(indexes)) - XCTAssertEqual(result.count, items.count) + XCTAssertEqual(result.flatMap({$0}).count, items.count) return true } @@ -168,13 +168,13 @@ class ValueWithObjectMetadataTests: XCTestCase { return true } - func checkTransactionDidReadMetadataItems(_ result: [MetadataTypeUnderTest]) -> Bool { + func checkTransactionDidReadMetadataItems(_ result: [MetadataTypeUnderTest?]) -> Bool { XCTAssertTrue(readTransaction.didReadAtIndexes.isEmpty) - if result.isEmpty { + if result.flatMap({$0}).isEmpty { return false } XCTAssertEqual(Set(readTransaction.didReadMetadataAtIndexes), Set(indexes)) - XCTAssertEqual(result.count, items.count) + XCTAssertEqual(result.flatMap({$0}).count, items.count) return true } diff --git a/Tests/ValueWithValueMetadataTests.swift b/Tests/ValueWithValueMetadataTests.swift index 3efce5f..15abf66 100644 --- a/Tests/ValueWithValueMetadataTests.swift +++ b/Tests/ValueWithValueMetadataTests.swift @@ -147,12 +147,12 @@ class ValueWithValueMetadataTests: XCTestCase { return true } - func checkTransactionDidReadItems(_ result: [YapItem]) -> Bool { - if result.isEmpty { + func checkTransactionDidReadItems(_ result: [YapItem?]) -> Bool { + if result.flatMap({$0}).isEmpty { return false } XCTAssertEqual(Set(readTransaction.didReadAtIndexes), Set(indexes)) - XCTAssertEqual(result.count, items.count) + XCTAssertEqual(result.flatMap({$0}).count, items.count) return true } @@ -166,13 +166,13 @@ class ValueWithValueMetadataTests: XCTestCase { return true } - func checkTransactionDidReadMetadataItems(_ result: [MetadataTypeUnderTest]) -> Bool { + func checkTransactionDidReadMetadataItems(_ result: [MetadataTypeUnderTest?]) -> Bool { XCTAssertTrue(readTransaction.didReadAtIndexes.isEmpty) - if result.isEmpty { + if result.flatMap({$0}).isEmpty { return false } XCTAssertEqual(Set(readTransaction.didReadMetadataAtIndexes), Set(indexes)) - XCTAssertEqual(result.count, items.count) + XCTAssertEqual(result.flatMap({$0}).count, items.count) return true } From 0a28f8d3a49408c13f7d3b1c056f2c06c4918ae7 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Sat, 31 Dec 2016 12:37:21 -0800 Subject: [PATCH 42/54] added more detail to the CHANGELOG. --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfdd7d0..b11f044 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # 3.0.0 -1. Separated Metadata from Objects +1. Separated Metadata from Objects (removed `metadata` from `Persistable`) 2. Updated for Swift 3.0 +3. Pod name changed to RCSYapDatabaseExtensions +4. Use `map` instead of `flatMap` when reading multiple objects so the order of the output corresponds to the order of the input. # 2.6.0 Updated for Swift 2.3 - sorry it's taken so long! From 76a94a9172d67e3b8a509d2f5d2fd4b5aeaa4e9e Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Sat, 31 Dec 2016 12:45:23 -0800 Subject: [PATCH 43/54] when checking if an extension is registered, cast to YapDatabaseExtension, not YapDatabaseView. Also, make isRegisteredInDatabase public, reverting the change made by the Swift 3 converter. --- Sources/YapDB.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/YapDB.swift b/Sources/YapDB.swift index f626b02..bfe133e 100644 --- a/Sources/YapDB.swift +++ b/Sources/YapDB.swift @@ -103,8 +103,8 @@ extension YapDB { - parameter database: a YapDatabase instance - returns: A Bool */ - open func isRegisteredInDatabase(_ database: YapDatabase) -> Bool { - return (database.registeredExtension(name) as? YapDatabaseView) != .none + public func isRegisteredInDatabase(_ database: YapDatabase) -> Bool { + return (database.registeredExtension(name) as? YapDatabaseExtension) != .none } } From 10aa640e777c79d7c46b54e331692ed4b6bc7c21 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Sat, 31 Dec 2016 13:06:00 -0800 Subject: [PATCH 44/54] default does not need to be surrounded in backticks, and enum types can be inferred. --- Sources/YapDatabaseExtensions.swift | 2 +- Tests/ObjectWithNoMetadataTests.swift | 2 +- Tests/ObjectWithObjectMetadataTests.swift | 2 +- Tests/ObjectWithValueMetadataTests.swift | 2 +- Tests/ValueWithNoMetadataTests.swift | 2 +- Tests/ValueWithObjectMetadataTests.swift | 2 +- Tests/ValueWithValueMetadataTests.swift | 2 +- Tests/YapDatabaseExtensionsTests.swift | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/YapDatabaseExtensions.swift b/Sources/YapDatabaseExtensions.swift index 365d32f..5cbf223 100644 --- a/Sources/YapDatabaseExtensions.swift +++ b/Sources/YapDatabaseExtensions.swift @@ -109,7 +109,7 @@ public struct YapDB { let path = pathToDatabase(.cachesDirectory, name: (file as NSString).lastPathComponent, suffix: test.trimmingCharacters(in: CharacterSet(charactersIn: "()"))) assert(!path.isEmpty, "Path should not be empty.") do { - try FileManager.`default`.removeItem(atPath: path) + try FileManager.default.removeItem(atPath: path) } catch { } diff --git a/Tests/ObjectWithNoMetadataTests.swift b/Tests/ObjectWithNoMetadataTests.swift index bb22b11..21e6963 100644 --- a/Tests/ObjectWithNoMetadataTests.swift +++ b/Tests/ObjectWithNoMetadataTests.swift @@ -50,7 +50,7 @@ class ObjectWithNoMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) + dispatchQueue = DispatchQueue.global(qos: .default) operationQueue = OperationQueue() } diff --git a/Tests/ObjectWithObjectMetadataTests.swift b/Tests/ObjectWithObjectMetadataTests.swift index eb3139c..21bd9f6 100644 --- a/Tests/ObjectWithObjectMetadataTests.swift +++ b/Tests/ObjectWithObjectMetadataTests.swift @@ -53,7 +53,7 @@ class ObjectWithObjectMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) + dispatchQueue = DispatchQueue.global(qos: .default) operationQueue = OperationQueue() } diff --git a/Tests/ObjectWithValueMetadataTests.swift b/Tests/ObjectWithValueMetadataTests.swift index 339a60f..65336db 100644 --- a/Tests/ObjectWithValueMetadataTests.swift +++ b/Tests/ObjectWithValueMetadataTests.swift @@ -53,7 +53,7 @@ class ObjectWithValueMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) + dispatchQueue = DispatchQueue.global(qos: .default) operationQueue = OperationQueue() } diff --git a/Tests/ValueWithNoMetadataTests.swift b/Tests/ValueWithNoMetadataTests.swift index 50e9364..4d1d89d 100644 --- a/Tests/ValueWithNoMetadataTests.swift +++ b/Tests/ValueWithNoMetadataTests.swift @@ -52,7 +52,7 @@ class ValueWithNoMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) + dispatchQueue = DispatchQueue.global(qos: .default) operationQueue = OperationQueue() } diff --git a/Tests/ValueWithObjectMetadataTests.swift b/Tests/ValueWithObjectMetadataTests.swift index e552ae5..aa3fd3d 100644 --- a/Tests/ValueWithObjectMetadataTests.swift +++ b/Tests/ValueWithObjectMetadataTests.swift @@ -53,7 +53,7 @@ class ValueWithObjectMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) + dispatchQueue = DispatchQueue.global(qos: .default) operationQueue = OperationQueue() } diff --git a/Tests/ValueWithValueMetadataTests.swift b/Tests/ValueWithValueMetadataTests.swift index 15abf66..5453217 100644 --- a/Tests/ValueWithValueMetadataTests.swift +++ b/Tests/ValueWithValueMetadataTests.swift @@ -53,7 +53,7 @@ class ValueWithValueMetadataTests: XCTestCase { connection.writeTransaction = writeTransaction database.connection = connection - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) + dispatchQueue = DispatchQueue.global(qos: .default) operationQueue = OperationQueue() } diff --git a/Tests/YapDatabaseExtensionsTests.swift b/Tests/YapDatabaseExtensionsTests.swift index 9feba7d..b14886a 100644 --- a/Tests/YapDatabaseExtensionsTests.swift +++ b/Tests/YapDatabaseExtensionsTests.swift @@ -141,7 +141,7 @@ class YapDatabaseConnectionTests: ReadWriteBaseTests { override func setUp() { super.setUp() - dispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.`default`) + dispatchQueue = DispatchQueue.global(qos: .default) operationQueue = OperationQueue() } From 5456e25651ed3661d15b5c2073246cb3a3484400 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Sat, 31 Dec 2016 13:08:27 -0800 Subject: [PATCH 45/54] add another availability modifier to help people refactor from code using CodingType. --- Sources/YapDatabaseExtensions.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/YapDatabaseExtensions.swift b/Sources/YapDatabaseExtensions.swift index 5cbf223..77e5282 100644 --- a/Sources/YapDatabaseExtensions.swift +++ b/Sources/YapDatabaseExtensions.swift @@ -637,7 +637,7 @@ public typealias ValueMetadataPersistable = Persistable public typealias Saveable = ValueCoding @available(*, unavailable, renamed: "CodingProtocol") -public typealias Archiver = CodingProtocol - - +public typealias CodingType = CodingProtocol +@available(*, unavailable, renamed: "CodingProtocol") +public typealias Archiver = CodingProtocol From 9a0a549055dac073231bd5d8a6dbf43fe205b99d Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Sat, 31 Dec 2016 13:16:24 -0800 Subject: [PATCH 46/54] Nothing in the Tests folder needs to be open for these tests to pass, so undo the changes by the Swift 3 converter. --- Tests/Models.swift | 52 +++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/Tests/Models.swift b/Tests/Models.swift index a33dd32..f447a0a 100644 --- a/Tests/Models.swift +++ b/Tests/Models.swift @@ -50,10 +50,10 @@ public struct Inventory: Identifiable, Equatable { } } -open class NamedEntity: NSObject, NSCoding { +public class NamedEntity: NSObject, NSCoding { - open let identifier: Identifier - open let name: String + public let identifier: Identifier + public let name: String public init(id: String, name n: String) { identifier = id @@ -65,18 +65,18 @@ open class NamedEntity: NSObject, NSCoding { name = aDecoder.decodeObject(forKey: "name") as! String } - open func encode(with aCoder: NSCoder) { + public func encode(with aCoder: NSCoder) { aCoder.encode(identifier, forKey: "identifier") aCoder.encode(name, forKey: "name") } } -open class Person: NamedEntity { } +public class Person: NamedEntity { } -open class Employee: NamedEntity { +public class Employee: NamedEntity { } -open class Manager: NamedEntity { +public class Manager: NamedEntity { public struct Metadata: Equatable { public let numberOfDirectReports: Int } @@ -149,7 +149,7 @@ extension Manager.Metadata: Hashable { extension NamedEntity { - open override var description: String { + public override var description: String { return "id: \(identifier), name: \(name)" } } @@ -253,8 +253,8 @@ extension Manager.Metadata: ValueCoding { // MARK: - Coders -open class BarcodeCoder: NSObject, NSCoding, CodingProtocol { - open let value: Barcode +public class BarcodeCoder: NSObject, NSCoding, CodingProtocol { + public let value: Barcode public required init(_ v: Barcode) { value = v @@ -279,7 +279,7 @@ open class BarcodeCoder: NSObject, NSCoding, CodingProtocol { } } - open func encode(with aCoder: NSCoder) { + public func encode(with aCoder: NSCoder) { aCoder.encode(value.kind.rawValue, forKey: "kind") switch value { case let .upca(numberSystem, manufacturer, product, check): @@ -293,8 +293,8 @@ open class BarcodeCoder: NSObject, NSCoding, CodingProtocol { } } -open class ProductCategoryCoder: NSObject, NSCoding, CodingProtocol { - open let value: Product.Category +public class ProductCategoryCoder: NSObject, NSCoding, CodingProtocol { + public let value: Product.Category public required init(_ v: Product.Category) { value = v @@ -306,14 +306,14 @@ open class ProductCategoryCoder: NSObject, NSCoding, CodingProtocol { value = Product.Category(identifier: identifier, name: name!) } - open func encode(with aCoder: NSCoder) { + public func encode(with aCoder: NSCoder) { aCoder.encode(value.identifier, forKey: "identifier") aCoder.encode(value.name, forKey: "name") } } -open class ProductMetadataCoder: NSObject, NSCoding, CodingProtocol { - open let value: Product.Metadata +public class ProductMetadataCoder: NSObject, NSCoding, CodingProtocol { + public let value: Product.Metadata public required init(_ v: Product.Metadata) { value = v @@ -324,13 +324,13 @@ open class ProductMetadataCoder: NSObject, NSCoding, CodingProtocol { value = Product.Metadata(categoryIdentifier: categoryIdentifier) } - open func encode(with aCoder: NSCoder) { + public func encode(with aCoder: NSCoder) { aCoder.encode(value.categoryIdentifier, forKey: "categoryIdentifier") } } -open class ProductCoder: NSObject, NSCoding, CodingProtocol { - open let value: Product +public class ProductCoder: NSObject, NSCoding, CodingProtocol { + public let value: Product public required init(_ v: Product) { value = v @@ -343,15 +343,15 @@ open class ProductCoder: NSObject, NSCoding, CodingProtocol { value = Product(identifier: identifier, name: name, barcode: barcode!) } - open func encode(with aCoder: NSCoder) { + public func encode(with aCoder: NSCoder) { aCoder.encode(value.identifier, forKey: "identifier") aCoder.encode(value.name, forKey: "name") aCoder.encode(value.barcode.encoded, forKey: "barcode") } } -open class InventoryCoder: NSObject, NSCoding, CodingProtocol { - open let value: Inventory +public class InventoryCoder: NSObject, NSCoding, CodingProtocol { + public let value: Inventory public required init(_ v: Inventory) { value = v @@ -362,14 +362,14 @@ open class InventoryCoder: NSObject, NSCoding, CodingProtocol { value = Inventory(product: product!) } - open func encode(with aCoder: NSCoder) { + public func encode(with aCoder: NSCoder) { aCoder.encode(value.product.encoded, forKey: "product") } } -open class ManagerMetadataCoder: NSObject, NSCoding, CodingProtocol { - open let value: Manager.Metadata +public class ManagerMetadataCoder: NSObject, NSCoding, CodingProtocol { + public let value: Manager.Metadata public required init(_ v: Manager.Metadata) { value = v @@ -380,7 +380,7 @@ open class ManagerMetadataCoder: NSObject, NSCoding, CodingProtocol { value = Manager.Metadata(numberOfDirectReports: numberOfDirectReports) } - open func encode(with aCoder: NSCoder) { + public func encode(with aCoder: NSCoder) { aCoder.encode(value.numberOfDirectReports, forKey: "numberOfDirectReports") } } From f5254f48dbc02203247a00beb908f63aa0bf5910 Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Fri, 6 Jan 2017 11:09:01 -0800 Subject: [PATCH 47/54] update README for the fork --- README.md | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 59847f1..d39f6ed 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ -![](https://raw.githubusercontent.com/danthorpe/YapDatabaseExtensions/development/header.png) +![](https://raw.githubusercontent.com/JimRoepcke/RCSYapDatabaseExtensions/development/header.png) -[![Build status](https://badge.buildkite.com/95784c169af7db5e36cefe146d5d3f3899c8339d46096a6349.svg)](https://buildkite.com/danthorpe/yapdatabaseextensions?branch=development) -[![Coverage Status](https://coveralls.io/repos/github/danthorpe/YapDatabaseExtensions/badge.svg?branch=development)](https://coveralls.io/github/danthorpe/YapDatabaseExtensions?branch=development) -[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/YapDatabaseExtensions.svg)](https://img.shields.io/cocoapods/v/YapDatabaseExtensions.svg) -[![CocoaPods Documentation](https://img.shields.io/cocoapods/metrics/doc-percent/YapDatabaseExtensions.svg?style=flat)](https://cocoapods.org/pods/YapDatabaseExtensions) -[![Platform](https://img.shields.io/cocoapods/p/YapDatabaseExtensions.svg?style=flat)](http://cocoadocs.org/docsets/YapDatabaseExtensions) +[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/RCSYapDatabaseExtensions.svg)](https://img.shields.io/cocoapods/v/RCSYapDatabaseExtensions.svg) +[![CocoaPods Documentation](https://img.shields.io/cocoapods/metrics/doc-percent/RCSYapDatabaseExtensions.svg?style=flat)](https://cocoapods.org/pods/RCSYapDatabaseExtensions) +[![Platform](https://img.shields.io/cocoapods/p/RCSYapDatabaseExtensions.svg?style=flat)](http://cocoadocs.org/docsets/RCSYapDatabaseExtensions) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) -# YapDatabaseExtensions +# RCSYapDatabaseExtensions -Read my introductory blog post about [YapDatabase & YapDatabaseExtensions](http://danthorpe.me/posts/yap-database.html), and a follow up on [YapDatabaseExtensions 2](http://danthorpe.me/posts/yapdatabaseextensions-two--the-swiftening.html). +**This is a fork of Dan Thorpe's YapDatabaseExtensions. It was created as my client needed a Swift 3 version immediately, but it also has several other enhancements. Please see CHANGELOG.md for details.** -YapDatabaseExtensions is a suite of convenience APIs for working with [YapDatabase](https://github.com/yapstudios/YapDatabase). If you’re not familiar with YapDatabase, it’s a powerful key value database for iOS and Mac - [check it out](https://github.com/yapstudios/YapDatabase)! +Read Dan Thorpe's introductory blog post about [YapDatabase & YapDatabaseExtensions](http://danthorpe.me/posts/yap-database.html), and a follow up on [YapDatabaseExtensions 2](http://danthorpe.me/posts/yapdatabaseextensions-two--the-swiftening.html). + +RCSYapDatabaseExtensions is a suite of convenience APIs for working with [YapDatabase](https://github.com/yapstudios/YapDatabase). If you’re not familiar with YapDatabase, it’s a powerful key value database for iOS and Mac - [check it out](https://github.com/yapstudios/YapDatabase)! ## Motivation While YapDatabase is great, it’s lacking some out of the box convenience and Swift support. In particular, YapDatabase works heavily with `AnyObject` types, which is fine for Objective-C but means no type fidelity with Swift. Similarly saving value types like structs or enums in YapDatabase is problematic. This framework has evolved through 2015 to tackle these issues. ## Value Types -The support for encoding and decoding value types, previously the `Saveable` and `Archiver` protocols, has been renamed and moved to their own project. [ValueCoding](https://github.com/danthorpe/ValueCoding) is a dependency of this framework (along with YapDatabase itself). See its [README](https://github.com/danthorpe/ValueCoding/blob/development/README.md) for more info. However, essentially, if you used this project before version 2.1, you’ll need to rename some types - and Xcode should present Fix It options. `Saveable` is now `ValueCoding`, its nested type, previously `ArchiverType` is now `Coder`, and this type must conform to a protocol, previously `Archiver`, now `CodingType`. See how they were all mixed up? Now fixed. +The support for encoding and decoding value types, previously the `Saveable` and `Archiver` protocols, has been renamed and moved to their own project. [ValueCoding](https://github.com/danthorpe/ValueCoding) is a dependency of this framework (along with YapDatabase itself). See its [README](https://github.com/danthorpe/ValueCoding/blob/development/README.md) for more info. However, essentially, if you used this project before version 2.1, you’ll need to rename some types - and Xcode should present Fix It options. `Saveable` is now `ValueCoding`, its nested type, previously `ArchiverType` is now `Coder`, and this type must conform to a protocol, previously `Archiver`, now `CodingProtocol`. See how they were all mixed up? Now fixed. ## `Persistable` This protocol expresses what is required to support reading from and writing to YapDatabase. Objects are referenced inside the database with a key (a `String`) inside a collection (also a `String`). @@ -40,11 +40,13 @@ While not a requirement of YapDatabase, for these extensions, it is required tha There is also a `YapDB.Index` struct which composes the key and collection into a single type. This is used internally for all access methods. Properties defined in an extension on `Persistable` provide access to `key` and `index`. ### Metadata -YapDatabase supports storing metadata alongside the primary object. YapDatabaseExtensions supports optional reading and writing of metadata alongside a `Persistable` type. +YapDatabase supports storing metadata alongside the primary object. RCSYapDatabaseExtensions supports optional reading and writing of metadata alongside a `Persistable` type. Your custom metadata types must conform to either `NSCoding` or `ValueCoding`. -In this version of YapDatabaseExtensions, metadata has been removed from `Persistable`, and all reads and writes of metadata must be done explicitly. Additionally, since the `MetadataType` is decoupled from the `Persistable` type, a single `Persistable` type can use many different types of metadata, as appropriate. When you want to read or write a value and it's metadata together, you use the "withMetadata" variants of the API, which accept and return `YapItem` values. `YapItem` is basically a slightly nicer wrapper than a Swift tuple, which can be extended, unlike anonymous tuple types. +**In this fork of YapDatabaseExtensions, metadata has been removed from `Persistable`, and all reads and writes of metadata must be done explicitly.** + +Additionally, since the `MetadataType` is decoupled from the `Persistable` type, a single `Persistable` type can use many different types of metadata, as appropriate. When you want to read or write a value and it's metadata together, you use the "withMetadata" variants of the API, which accept and return `YapItem` values. `YapItem` is basically a slightly nicer wrapper than a Swift tuple, which can be extended, unlike anonymous tuple types. ## “Correct” Type Patterns Because the generic protocols, `ValueCoding` and `CodingType` have self-reflective properties, they must be correctly implemented for the APIs to be available. This means that the equality `ValueCoding.Coder.ValueType == Self` must be met. The APIs are all composed with this represented in their generic where clauses. This means that if your `ValueCoding` type is not the `ValueType` of its `Coder`, your code will not compile. @@ -62,7 +64,7 @@ Item encoding | Metadata encoding | Pattern ## Extension APIs -YapDatabaseExtensions provides two styles of API. The *functional* API works on `YapDatabase` types, `YapDatabaseReadTransaction`, `YapDatabaseReadWriteTransaction` and `YapDatabaseConnection`. The *persistable* API works on your `Persistable` types directly, and receives the `YapDatabase` type as arguments. +RCSYapDatabaseExtensions provides two styles of API. The *functional* API works on `YapDatabase` types, `YapDatabaseReadTransaction`, `YapDatabaseReadWriteTransaction` and `YapDatabaseConnection`. The *persistable* API works on your `Persistable` types directly, and receives the `YapDatabase` type as arguments. ### Functional API @@ -200,22 +202,22 @@ let (items, missingKeys) = Item.read(connection).filterExisting(someKeys) ## Installation -YapDatabaseExtensions is available through [CocoaPods](http://cocoapods.org). To install +RCSYapDatabaseExtensions is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile: ```ruby -pod 'YapDatabaseExtensions' +pod 'RCSYapDatabaseExtensions' ``` If you don’t want the extensions API on `Persistable`, integrate the Functional subspec like this: ```ruby -pod 'YapDatabaseExtensions/Functional’ +pod 'RCSYapDatabaseExtensions/Functional’ ``` ## API Documentation -API documentation is available on [CocoaDocs.org](http://cocoadocs.org/docsets/YapDatabaseExtensions). +API documentation is available on [CocoaDocs.org](http://cocoadocs.org/docsets/RCSYapDatabaseExtensions). ## Developing @@ -228,4 +230,4 @@ Jim Roepcke, [@JimRoepcke](https://twitter.com/JimRoepcke) ## License -YapDatabaseExtensions is available under the MIT license. See the LICENSE file for more info. +RCSYapDatabaseExtensions is available under the MIT license. See the LICENSE file for more info. From 94f1a6b0a3c247d0c00c32862be8e15edd31f21c Mon Sep 17 00:00:00 2001 From: Jim Roepcke Date: Thu, 27 Apr 2017 12:16:41 -0700 Subject: [PATCH 48/54] chore: accept new versions of YapDatabase 2.9.x, and bump to 3.0.1 --- RCSYapDatabaseExtensions.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RCSYapDatabaseExtensions.podspec b/RCSYapDatabaseExtensions.podspec index 013359a..6bfe393 100644 --- a/RCSYapDatabaseExtensions.podspec +++ b/RCSYapDatabaseExtensions.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "RCSYapDatabaseExtensions" - s.version = "3.0.0" + s.version = "3.0.1" s.summary = "Helpers for using value types with YapDatabase." s.description = <<-DESC @@ -23,7 +23,7 @@ Pod::Spec.new do |s| s.osx.deployment_target = '10.11' s.dependency 'ValueCoding', '~> 2.1.0' - s.dependency 'YapDatabase', '2.9.2' + s.dependency 'YapDatabase', '~> 2.9.2' s.subspec 'Core' do |ss| ss.source_files = [ From b88870418bca4bde53d7990de161801f9acc821b Mon Sep 17 00:00:00 2001 From: Andrey Yastrebov Date: Fri, 27 Oct 2017 19:39:08 +0300 Subject: [PATCH 49/54] - update --- Cartfile | 5 ++--- Cartfile.resolved | 6 ++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Cartfile b/Cartfile index 034481a..144a06f 100644 --- a/Cartfile +++ b/Cartfile @@ -1,3 +1,2 @@ -github "danthorpe/ValueCoding" "1.5.0" -github "CocoaLumberjack/CocoaLumberjack" "2.4.0" -github "yapstudios/YapDatabase" "2.9.2" \ No newline at end of file +github "CocoaLumberjack/CocoaLumberjack" "3.3.0" +github "yapstudios/YapDatabase" ~> 3.0.0 diff --git a/Cartfile.resolved b/Cartfile.resolved index 8ae8b91..1e4b32d 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,4 +1,2 @@ -github "CocoaLumberjack/CocoaLumberjack" "2.4.0" -github "tonymillion/Reachability" "c4d225a479379f9998dbd5b55070427373d20574" -github "danthorpe/ValueCoding" "1.5.0" -github "yapstudios/YapDatabase" "2.9.2" +github "CocoaLumberjack/CocoaLumberjack" "3.3.0" +github "yapstudios/YapDatabase" "3.0.2" From 9c28a087de97a38059ea536d6ac6614ce523b9f6 Mon Sep 17 00:00:00 2001 From: Andrey Yastrebov Date: Fri, 27 Oct 2017 19:51:45 +0300 Subject: [PATCH 50/54] - wip --- Cartfile | 3 ++- Cartfile.resolved | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Cartfile b/Cartfile index 144a06f..1d07f61 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,3 @@ -github "CocoaLumberjack/CocoaLumberjack" "3.3.0" +github "CocoaLumberjack/CocoaLumberjack" ~> 3.3.0 github "yapstudios/YapDatabase" ~> 3.0.0 +github "danthorpe/ValueCoding" ~> 3.0.0 diff --git a/Cartfile.resolved b/Cartfile.resolved index 1e4b32d..f4c9ab0 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,3 @@ github "CocoaLumberjack/CocoaLumberjack" "3.3.0" +github "danthorpe/ValueCoding" "3.0.0" github "yapstudios/YapDatabase" "3.0.2" From a36e9f3b2ae0d66d248e14dd157b8f22640a37c7 Mon Sep 17 00:00:00 2001 From: Andrey Yastrebov Date: Sun, 29 Oct 2017 18:42:27 +0300 Subject: [PATCH 51/54] - wip --- .ruby-version | 1 + .swift-version | 2 +- Cartfile | 4 +- Cartfile.resolved | 6 +- Sources/YapDB.swift | 1 + .../project.pbxproj | 62 ++++++++++++++++--- .../xcschemes/YapDatabaseExtensions.xcscheme | 4 +- 7 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..197c4d5 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.4.0 diff --git a/.swift-version b/.swift-version index c0943d3..5186d07 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -2.3 \ No newline at end of file +4.0 diff --git a/Cartfile b/Cartfile index 00e0c1c..c533da3 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ -github "danthorpe/ValueCoding" "2.1.0" -github "yapstudios/YapDatabase" "2.9.3" \ No newline at end of file +github "danthorpe/ValueCoding" ~> 3.0.0 +github "yapstudios/YapDatabase" ~> 3.0.0 diff --git a/Cartfile.resolved b/Cartfile.resolved index f10e04c..f4c9ab0 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,3 @@ -github "CocoaLumberjack/CocoaLumberjack" "3.0.0" -github "danthorpe/ValueCoding" "2.1.0" -github "yapstudios/YapDatabase" "2.9.3" +github "CocoaLumberjack/CocoaLumberjack" "3.3.0" +github "danthorpe/ValueCoding" "3.0.0" +github "yapstudios/YapDatabase" "3.0.2" diff --git a/Sources/YapDB.swift b/Sources/YapDB.swift index bfe133e..c455154 100644 --- a/Sources/YapDB.swift +++ b/Sources/YapDB.swift @@ -7,6 +7,7 @@ import YapDatabase.YapDatabaseView import YapDatabase.YapDatabaseFilteredView import YapDatabase.YapDatabaseFullTextSearch import YapDatabase.YapDatabaseSecondaryIndex +import YapDatabase.YapDatabaseAutoView protocol YapDatabaseViewProducer { func createDatabaseView() -> YapDatabaseView diff --git a/YapDatabaseExtensions.xcodeproj/project.pbxproj b/YapDatabaseExtensions.xcodeproj/project.pbxproj index dd69886..3a99413 100644 --- a/YapDatabaseExtensions.xcodeproj/project.pbxproj +++ b/YapDatabaseExtensions.xcodeproj/project.pbxproj @@ -46,6 +46,10 @@ 65E6DB801DA155700037A1AA /* ValueWithObjectMetadataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E6DB751DA155700037A1AA /* ValueWithObjectMetadataTests.swift */; }; 65E6DB811DA155700037A1AA /* ValueWithValueMetadataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E6DB761DA155700037A1AA /* ValueWithValueMetadataTests.swift */; }; 65E6DB821DA155700037A1AA /* YapDatabaseExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E6DB771DA155700037A1AA /* YapDatabaseExtensionsTests.swift */; }; + BC69409C1FA62CBF00658E7C /* CocoaLumberjackSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC6940981FA62CBE00658E7C /* CocoaLumberjackSwift.framework */; }; + BC69409D1FA62CBF00658E7C /* CocoaLumberjack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC6940991FA62CBE00658E7C /* CocoaLumberjack.framework */; }; + BC69409E1FA62CBF00658E7C /* ValueCoding.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC69409A1FA62CBE00658E7C /* ValueCoding.framework */; }; + BC69409F1FA62CBF00658E7C /* YapDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC69409B1FA62CBE00658E7C /* YapDatabase.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -104,6 +108,10 @@ 65E6DB751DA155700037A1AA /* ValueWithObjectMetadataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueWithObjectMetadataTests.swift; sourceTree = ""; }; 65E6DB761DA155700037A1AA /* ValueWithValueMetadataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValueWithValueMetadataTests.swift; sourceTree = ""; }; 65E6DB771DA155700037A1AA /* YapDatabaseExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YapDatabaseExtensionsTests.swift; sourceTree = ""; }; + BC6940981FA62CBE00658E7C /* CocoaLumberjackSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CocoaLumberjackSwift.framework; path = Carthage/Build/iOS/CocoaLumberjackSwift.framework; sourceTree = ""; }; + BC6940991FA62CBE00658E7C /* CocoaLumberjack.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CocoaLumberjack.framework; path = Carthage/Build/iOS/CocoaLumberjack.framework; sourceTree = ""; }; + BC69409A1FA62CBE00658E7C /* ValueCoding.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ValueCoding.framework; path = Carthage/Build/iOS/ValueCoding.framework; sourceTree = ""; }; + BC69409B1FA62CBE00658E7C /* YapDatabase.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = YapDatabase.framework; path = Carthage/Build/iOS/YapDatabase.framework; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -111,6 +119,10 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + BC69409C1FA62CBF00658E7C /* CocoaLumberjackSwift.framework in Frameworks */, + BC69409D1FA62CBF00658E7C /* CocoaLumberjack.framework in Frameworks */, + BC69409E1FA62CBF00658E7C /* ValueCoding.framework in Frameworks */, + BC69409F1FA62CBF00658E7C /* YapDatabase.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -132,6 +144,7 @@ 65E6DB6C1DA155700037A1AA /* Tests */, 65D2CBE31D9BF4880088AB4F /* Supporting Files */, 656BAE711D9A4CCC008279EE /* Products */, + BC6940971FA62CBE00658E7C /* Frameworks */, ); sourceTree = ""; }; @@ -208,6 +221,17 @@ path = Tests; sourceTree = ""; }; + BC6940971FA62CBE00658E7C /* Frameworks */ = { + isa = PBXGroup; + children = ( + BC6940991FA62CBE00658E7C /* CocoaLumberjack.framework */, + BC6940981FA62CBE00658E7C /* CocoaLumberjackSwift.framework */, + BC69409A1FA62CBE00658E7C /* ValueCoding.framework */, + BC69409B1FA62CBE00658E7C /* YapDatabase.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -266,15 +290,15 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0810; + LastUpgradeCheck = 0900; TargetAttributes = { 656BAE6F1D9A4CCC008279EE = { CreatedOnToolsVersion = 7.3.1; - LastSwiftMigration = 0820; + LastSwiftMigration = 0900; }; 656BAE791D9A4CCC008279EE = { CreatedOnToolsVersion = 7.3.1; - LastSwiftMigration = 0820; + LastSwiftMigration = 0900; }; }; }; @@ -401,12 +425,18 @@ isa = XCBuildConfiguration; baseConfigurationReference = 65D2CBE81D9BF4880088AB4F /* YapDatabaseExtensions.xcconfig */; buildSettings = { + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -427,12 +457,18 @@ isa = XCBuildConfiguration; baseConfigurationReference = 65D2CBE81D9BF4880088AB4F /* YapDatabaseExtensions.xcconfig */; buildSettings = { + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -475,6 +511,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); FRAMEWORK_VERSION = A; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; @@ -496,7 +536,8 @@ ONLY_ACTIVE_ARCH = YES; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -529,6 +570,10 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); FRAMEWORK_VERSION = A; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; @@ -542,7 +587,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -592,7 +638,8 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -632,7 +679,8 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/YapDatabaseExtensions.xcodeproj/xcshareddata/xcschemes/YapDatabaseExtensions.xcscheme b/YapDatabaseExtensions.xcodeproj/xcshareddata/xcschemes/YapDatabaseExtensions.xcscheme index b51b99f..ede265c 100644 --- a/YapDatabaseExtensions.xcodeproj/xcshareddata/xcschemes/YapDatabaseExtensions.xcscheme +++ b/YapDatabaseExtensions.xcodeproj/xcshareddata/xcschemes/YapDatabaseExtensions.xcscheme @@ -1,6 +1,6 @@ Date: Tue, 31 Oct 2017 01:22:12 +0300 Subject: [PATCH 52/54] - fixed build errors --- Sources/YapDB.swift | 48 +++++++++---------- .../project.pbxproj | 10 ++-- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/Sources/YapDB.swift b/Sources/YapDB.swift index c455154..51a9f0d 100644 --- a/Sources/YapDB.swift +++ b/Sources/YapDB.swift @@ -15,7 +15,7 @@ protocol YapDatabaseViewProducer { protocol YapDatabaseExtensionRegistrar { func isRegisteredInDatabase(_ database: YapDatabase) -> Bool - func registerInDatabase(_ database: YapDatabase, withConnection: YapDatabaseConnection?) + func registerInDatabase(_ database: YapDatabase, withConfig config: YapDatabaseConnectionConfig?) } extension YapDB { @@ -66,8 +66,8 @@ extension YapDB { - parameter database: a YapDatabase instance - parameter connection: an optional YapDatabaseConnection, defaults to .None */ - public func registerInDatabase(_ database: YapDatabase, withConnection connection: YapDatabaseConnection? = .none) { - registrar.registerInDatabase(database, withConnection: connection) + public func registerInDatabase(_ database: YapDatabase, withConfig config: YapDatabaseConnectionConfig? = .none) { + registrar.registerInDatabase(database, withConfig: config) } /** @@ -76,8 +76,8 @@ extension YapDB { - parameter database: a YapDatabase instance - parameter connection: an optional YapDatabaseConnection, defaults to .None */ - public func createViewMappings(_ mappings: Mappings, inDatabase database: YapDatabase, withConnection connection: YapDatabaseConnection? = .none) -> YapDatabaseViewMappings { - registerInDatabase(database, withConnection: connection) + public func createViewMappings(_ mappings: Mappings, inDatabase database: YapDatabase, withConfig config: YapDatabaseConnectionConfig? = .none) -> YapDatabaseViewMappings { + registerInDatabase(database, withConfig: config) return mappings.createMappingsWithViewName(name) } } @@ -221,13 +221,13 @@ extension YapDB { } func createDatabaseView() -> YapDatabaseView { - return YapDatabaseView(grouping: grouping.object(withOptions: groupingOptions), sorting: sorting.object(withOptions: sortingOptions), versionTag: version, options: options) + return YapDatabaseAutoView(grouping: grouping.object(withOptions: groupingOptions), sorting: sorting.object(withOptions: sortingOptions), versionTag: version, options: options) } - func registerInDatabase(_ database: YapDatabase, withConnection connection: YapDatabaseConnection? = .none) { + func registerInDatabase(_ database: YapDatabase, withConfig config: YapDatabaseConnectionConfig? = .none) { if !isRegisteredInDatabase(database) { - if let connection = connection { - database.register(createDatabaseView(), withName: name, connection: connection) + if let config = config { + database.register(createDatabaseView(), withName: name, config: config) } else { database.register(createDatabaseView(), withName: name) @@ -303,11 +303,11 @@ extension YapDB { return YapDatabaseFilteredView(parentViewName: parent.name, filtering: filtering.object(withOptions: filteringOptions), versionTag: version, options: options) } - func registerInDatabase(_ database: YapDatabase, withConnection connection: YapDatabaseConnection? = .none) { + func registerInDatabase(_ database: YapDatabase, withConfig config: YapDatabaseConnectionConfig? = .none) { if !isRegisteredInDatabase(database) { - parent.registerInDatabase(database, withConnection: connection) - if let connection = connection { - database.register(createDatabaseView(), withName: name, connection: connection) + parent.registerInDatabase(database, withConfig: config) + if let config = config { + database.register(createDatabaseView(), withName: name, config: config) } else { database.register(createDatabaseView(), withName: name) @@ -377,12 +377,12 @@ extension YapDB { return YapDatabaseSearchResultsView(fullTextSearchName: searchName, parentViewName: parent.name, versionTag: version, options: .none) } - func registerInDatabase(_ database: YapDatabase, withConnection connection: YapDatabaseConnection? = .none) { + func registerInDatabase(_ database: YapDatabase, withConfig config: YapDatabaseConnectionConfig? = .none) { if (database.registeredExtension(searchName) as? YapDatabaseFullTextSearch) == .none { let fullTextSearch = YapDatabaseFullTextSearch(columnNames: columnNames, options: nil, handler: handler.object, versionTag: version) - if let connection = connection { - database.register(fullTextSearch, withName: searchName, connection: connection) + if let config = config { + database.register(fullTextSearch, withName: searchName, config: config) } else { database.register(fullTextSearch, withName: searchName) @@ -390,9 +390,9 @@ extension YapDB { } if !isRegisteredInDatabase(database) { - parent.registerInDatabase(database, withConnection: connection) - if let connection = connection { - database.register(createDatabaseView(), withName: name, connection: connection) + parent.registerInDatabase(database, withConfig: config) + if let config = config { + database.register(createDatabaseView(), withName: name, config: config) } else { database.register(createDatabaseView(), withName: name) @@ -455,11 +455,11 @@ extension YapDB { return setup } - open func registerInDatabase(_ database: YapDatabase, withConnection connection: YapDatabaseConnection?) { + open func registerInDatabase(_ database: YapDatabase, withConfig config: YapDatabaseConnectionConfig?) { if !isRegisteredInDatabase(database) { let secondaryIndex = YapDatabaseSecondaryIndex(setup: setup(), handler: handler.object, versionTag: version, options: options) - if let connection = connection { - database.register(secondaryIndex, withName: name, connection: connection) + if let config = config { + database.register(secondaryIndex, withName: name, config: config) } else { database.register(secondaryIndex, withName: name) @@ -546,8 +546,8 @@ extension YapDB { self.init(fetch: .search(search)) } - public func createMappingsRegisteredInDatabase(_ database: YapDatabase, withConnection connection: YapDatabaseConnection? = .none) -> YapDatabaseViewMappings { - let databaseViewMappings = fetch.createViewMappings(mappings, inDatabase: database, withConnection: connection) + public func createMappingsRegisteredInDatabase(_ database: YapDatabase, withConfig config: YapDatabaseConnectionConfig? = .none) -> YapDatabaseViewMappings { + let databaseViewMappings = fetch.createViewMappings(mappings, inDatabase: database, withConfig: config) block?(databaseViewMappings) return databaseViewMappings } diff --git a/YapDatabaseExtensions.xcodeproj/project.pbxproj b/YapDatabaseExtensions.xcodeproj/project.pbxproj index 3a99413..1fe3d59 100644 --- a/YapDatabaseExtensions.xcodeproj/project.pbxproj +++ b/YapDatabaseExtensions.xcodeproj/project.pbxproj @@ -450,6 +450,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; ONLY_ACTIVE_ARCH = YES; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -481,6 +482,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -536,7 +538,7 @@ ONLY_ACTIVE_ARCH = YES; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -587,7 +589,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -638,7 +640,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Debug; @@ -679,7 +681,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Release; From d73af205a8372572260049e2aa6e9e170d8a6691 Mon Sep 17 00:00:00 2001 From: Andrey Yastrebov Date: Tue, 31 Oct 2017 03:04:37 +0300 Subject: [PATCH 53/54] - fixed tests --- Tests/ObjectWithNoMetadataTests.swift | 26 +++++++++++++---- Tests/ObjectWithObjectMetadataTests.swift | 27 +++++++++++++---- Tests/ObjectWithValueMetadataTests.swift | 29 +++++++++++++++---- .../project.pbxproj | 20 +++++++++++-- 4 files changed, 82 insertions(+), 20 deletions(-) diff --git a/Tests/ObjectWithNoMetadataTests.swift b/Tests/ObjectWithNoMetadataTests.swift index 21e6963..5c3efa0 100644 --- a/Tests/ObjectWithNoMetadataTests.swift +++ b/Tests/ObjectWithNoMetadataTests.swift @@ -93,9 +93,16 @@ class ObjectWithNoMetadataTests: XCTestCase { func checkTransactionDidWriteItem(_ result: TypeUnderTest) { XCTAssertEqual(result.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertNil(writeTransaction.didWriteAtIndexes[0].2) + + let _index = writeTransaction.didWriteAtIndexes[0].0 + let _identifier = writeTransaction.didWriteAtIndexes[0].1 as? TypeUnderTest + let _metadata = writeTransaction.didWriteAtIndexes[0].2 + + XCTAssertNotNil(_identifier?.identifier) + + XCTAssertEqual(_index, index) + XCTAssertEqual(_identifier?.identifier, item.identifier) + XCTAssertNil(_metadata) } func checkTransactionDidWriteItems(_ result: [TypeUnderTest]) { @@ -674,9 +681,16 @@ class Persistable_Write_ObjectWithNoMetadataTests: ObjectWithNoMetadataTests { operationQueue.addOperation(operation) waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertNil(writeTransaction.didWriteAtIndexes[0].2) + + let _index = writeTransaction.didWriteAtIndexes[0].0 + let _identifier = writeTransaction.didWriteAtIndexes[0].1 as? TypeUnderTest + let _metadata = writeTransaction.didWriteAtIndexes[0].2 + + XCTAssertNotNil(_identifier?.identifier) + + XCTAssertEqual(_index, index) + XCTAssertEqual(_identifier?.identifier, item.identifier) + XCTAssertNil(_metadata) XCTAssertTrue(connection.didWrite) } diff --git a/Tests/ObjectWithObjectMetadataTests.swift b/Tests/ObjectWithObjectMetadataTests.swift index 21bd9f6..c79acfd 100644 --- a/Tests/ObjectWithObjectMetadataTests.swift +++ b/Tests/ObjectWithObjectMetadataTests.swift @@ -103,9 +103,16 @@ class ObjectWithObjectMetadataTests: XCTestCase { func checkTransactionDidWriteItem(_ result: YapItem) { XCTAssertEqual(result.value.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSDate, metadata) + + let _index = writeTransaction.didWriteAtIndexes[0].0 + let _identifier = writeTransaction.didWriteAtIndexes[0].1 as? TypeUnderTest + let _metadata = writeTransaction.didWriteAtIndexes[0].2 + + XCTAssertNotNil(_identifier?.identifier) + + XCTAssertEqual(_index, index) + XCTAssertEqual(_identifier?.identifier, item.identifier) + XCTAssertEqual(_metadata as? NSDate, metadata) } func checkTransactionDidWriteItems(_ result: [YapItem]) { @@ -686,9 +693,17 @@ class Persistable_Write_ObjectWithObjectMetadataTests: ObjectWithObjectMetadataT operationQueue.addOperation(operation) waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].2 as? NSDate, metadata) + + let _index = writeTransaction.didWriteAtIndexes[0].0 + let _identifier = writeTransaction.didWriteAtIndexes[0].1 as? TypeUnderTest + let _metadata = writeTransaction.didWriteAtIndexes[0].2 + + XCTAssertNotNil(_identifier?.identifier) + + XCTAssertEqual(_index, index) + XCTAssertEqual(_identifier?.identifier, item.identifier) + XCTAssertEqual(_metadata as? NSDate, metadata) + XCTAssertTrue(connection.didWrite) } diff --git a/Tests/ObjectWithValueMetadataTests.swift b/Tests/ObjectWithValueMetadataTests.swift index 65336db..c2e6b73 100644 --- a/Tests/ObjectWithValueMetadataTests.swift +++ b/Tests/ObjectWithValueMetadataTests.swift @@ -107,9 +107,18 @@ class ObjectWithValueMetadataTests: XCTestCase { func checkTransactionDidWriteItem(_ result: YapItem) { XCTAssertEqual(result.value.identifier, item.identifier) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertEqual(MetadataTypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].2), metadata) + + let _index = writeTransaction.didWriteAtIndexes[0].0 + let _identifier = writeTransaction.didWriteAtIndexes[0].1 as? TypeUnderTest + let _metadata = writeTransaction.didWriteAtIndexes[0].2 + + XCTAssertNotNil(_identifier?.identifier) + + XCTAssertEqual(_index, index) + XCTAssertEqual(_identifier?.identifier, item.identifier) + XCTAssertNotNil(_metadata) + + XCTAssertEqual(MetadataTypeUnderTest.decode(_metadata), metadata) } func checkTransactionDidWriteItems(_ result: [YapItem]) { @@ -690,9 +699,17 @@ class Persistable_Write_ObjectWithValueMetadataTests: ObjectWithValueMetadataTes operationQueue.addOperation(operation) waitForExpectations(timeout: 3.0, handler: nil) XCTAssertFalse(writeTransaction.didWriteAtIndexes.isEmpty) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].0, index) - XCTAssertEqual(writeTransaction.didWriteAtIndexes[0].1.identifier, item.identifier) - XCTAssertEqual(MetadataTypeUnderTest.decode(writeTransaction.didWriteAtIndexes[0].2), metadata) + + let _index = writeTransaction.didWriteAtIndexes[0].0 + let _identifier = writeTransaction.didWriteAtIndexes[0].1 as? TypeUnderTest + let _metadata = writeTransaction.didWriteAtIndexes[0].2 + + XCTAssertNotNil(_identifier?.identifier) + + XCTAssertEqual(_index, index) + XCTAssertEqual(_identifier?.identifier, item.identifier) + XCTAssertEqual(MetadataTypeUnderTest.decode(_metadata), metadata) + XCTAssertTrue(connection.didWrite) } diff --git a/YapDatabaseExtensions.xcodeproj/project.pbxproj b/YapDatabaseExtensions.xcodeproj/project.pbxproj index 1fe3d59..ac1ecca 100644 --- a/YapDatabaseExtensions.xcodeproj/project.pbxproj +++ b/YapDatabaseExtensions.xcodeproj/project.pbxproj @@ -50,6 +50,10 @@ BC69409D1FA62CBF00658E7C /* CocoaLumberjack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC6940991FA62CBE00658E7C /* CocoaLumberjack.framework */; }; BC69409E1FA62CBF00658E7C /* ValueCoding.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC69409A1FA62CBE00658E7C /* ValueCoding.framework */; }; BC69409F1FA62CBF00658E7C /* YapDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC69409B1FA62CBE00658E7C /* YapDatabase.framework */; }; + BCE1D7CC1FA7ECFA00666455 /* CocoaLumberjack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC6940991FA62CBE00658E7C /* CocoaLumberjack.framework */; }; + BCE1D7CD1FA7ECFD00666455 /* CocoaLumberjackSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC6940981FA62CBE00658E7C /* CocoaLumberjackSwift.framework */; }; + BCE1D7CE1FA7ECFF00666455 /* ValueCoding.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC69409A1FA62CBE00658E7C /* ValueCoding.framework */; }; + BCE1D7CF1FA7ED0100666455 /* YapDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC69409B1FA62CBE00658E7C /* YapDatabase.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -130,7 +134,11 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + BCE1D7CC1FA7ECFA00666455 /* CocoaLumberjack.framework in Frameworks */, 656BAE7B1D9A4CCC008279EE /* YapDatabaseExtensions.framework in Frameworks */, + BCE1D7CF1FA7ED0100666455 /* YapDatabase.framework in Frameworks */, + BCE1D7CE1FA7ECFF00666455 /* ValueCoding.framework in Frameworks */, + BCE1D7CD1FA7ECFD00666455 /* CocoaLumberjackSwift.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -620,6 +628,10 @@ DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -634,7 +646,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks $(FRAMEWORK_SEARCH_PATHS)"; MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; @@ -669,6 +681,10 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -677,7 +693,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks $(FRAMEWORK_SEARCH_PATHS)"; MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; From 29edbbe506fe711b51730301e7fd7f27f6c7cef6 Mon Sep 17 00:00:00 2001 From: Andrey Yastrebov Date: Thu, 9 Nov 2017 18:22:56 +0300 Subject: [PATCH 54/54] - final touches --- .fastlane/Fastfile | 14 +- CHANGELOG.md | 12 +- Gemfile.lock | 315 ++++++------------ README.md | 86 ++--- ...s.podspec => YapDatabaseExtensions.podspec | 32 +- 5 files changed, 184 insertions(+), 275 deletions(-) rename RCSYapDatabaseExtensions.podspec => YapDatabaseExtensions.podspec (58%) diff --git a/.fastlane/Fastfile b/.fastlane/Fastfile index ef3b9c3..ef789f7 100644 --- a/.fastlane/Fastfile +++ b/.fastlane/Fastfile @@ -6,15 +6,15 @@ platform :ios do desc "Runs all the tests" lane :test do - + scan( - scheme: 'YapDatabaseExtensions', + scheme: 'YapDatabaseExtensions', output_directory: ".ci/xcodebuild-data", - destination: "platform=iOS Simulator,OS=10.1,name=iPhone 7" + destination: "platform=iOS Simulator,OS=11.1,name=iPhone 7" ) end - + end platform :mac do @@ -25,13 +25,13 @@ platform :mac do desc "Runs all the tests" lane :test do - + scan( - scheme: 'YapDatabaseExtensions', + scheme: 'YapDatabaseExtensions', output_directory: ".ci/xcodebuild-data", destination: "platform=OS X" ) end - + end diff --git a/CHANGELOG.md b/CHANGELOG.md index b11f044..17448b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ +# 4.0.0 +1. Updated for Swift 4.0 + # 3.0.0 1. Separated Metadata from Objects (removed `metadata` from `Persistable`) 2. Updated for Swift 3.0 -3. Pod name changed to RCSYapDatabaseExtensions 4. Use `map` instead of `flatMap` when reading multiple objects so the order of the output corresponds to the order of the input. # 2.6.0 @@ -56,7 +58,7 @@ Thanks a lot to Ryan ([@aranasaurus](https://github.com/aranasaurus)) for helpin # 2.1.0 1. [[YDB-42](https://github.com/danthorpe/YapDatabaseExtensions/pull/42)]: Refactors read & write API, correctly supporting metadata. 2. [[YDB-43](https://github.com/danthorpe/YapDatabaseExtensions/pull/43)]: Makes project cross-platform (iOS & Mac OS) -3. [[YDB-44](https://github.com/danthorpe/YapDatabaseExtensions/pull/44)]: Enables code coverage reporting with CodeCov.io, see reports [here](https://codecov.io/github/danthorpe/YapDatabaseExtensions). +3. [[YDB-44](https://github.com/danthorpe/YapDatabaseExtensions/pull/44)]: Enables code coverage reporting with CodeCov.io, see reports [here](https://codecov.io/github/danthorpe/YapDatabaseExtensions). 4. [[YDB-45](https://github.com/danthorpe/YapDatabaseExtensions/pull/45)]: Adds back functional API. 5. [[YDB-47](https://github.com/danthorpe/YapDatabaseExtensions/pull/47)]: Updates README. 6. [[YDB-48](https://github.com/danthorpe/YapDatabaseExtensions/pull/48)]: Removes `Saveable`, created [ValueCoding](https://github.com/danthorpe/ValueCoding) as a standalone project and new dependency. @@ -78,7 +80,7 @@ Thanks a lot to Ryan ([@aranasaurus](https://github.com/aranasaurus)) for helpin 4. [[YDB-29](https://github.com/danthorpe/YapDatabaseExtensions/pull/29)]: Adds support to `YapDatabaseConnection` for writeBlockOperation (`NSBlockOperation`), write and remove APIs. This is great if you want to perform a number of writes of different types in the same transaction inside of an `NSOperation` based architecture, as you can do: ```swift -queue.addOperation(connection.writeBlockOperation { transaction in +queue.addOperation(connection.writeBlockOperation { transaction in transaction.write(foo) transaction.write(bar) transaction.remove(bat) @@ -87,7 +89,7 @@ queue.addOperation(connection.writeBlockOperation { transaction in If you're using my `Operations` framework, as these operations are `NSBlockOperation`s, use `ComposedOperation` to attach conditions or observers. E.g. ```swift -let write = ComposedOperation(connection.writeBlockOperation { transaction in +let write = ComposedOperation(connection.writeBlockOperation { transaction in transaction.write(foo) transaction.write(bar) transaction.remove(bat) @@ -126,7 +128,7 @@ queue.addOperation(write) # 1.1.1 -1. [[YDB-11](https://github.com/danthorpe/YapDatabaseExtensions/pull/11)]: Renames `YapDatabase.Index` to `YapDB.Index`. +1. [[YDB-11](https://github.com/danthorpe/YapDatabaseExtensions/pull/11)]: Renames `YapDatabase.Index` to `YapDB.Index`. # 1.1.0 diff --git a/Gemfile.lock b/Gemfile.lock index 911cca6..c887d2e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,296 +1,202 @@ GEM remote: https://rubygems.org/ specs: - CFPropertyList (2.3.4) + CFPropertyList (2.3.5) RubyInline (3.12.4) ZenTest (~> 4.3) ZenTest (4.11.1) - activesupport (4.2.7.1) + activesupport (4.2.10) i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.5.0) - public_suffix (~> 2.0, >= 2.0.2) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) babosa (1.0.2) - cert (1.4.4) - fastlane_core (>= 0.55.0, < 1.0.0) - spaceship (>= 0.37.0, < 1.0.0) - claide (1.0.1) + claide (1.0.2) clamp (0.6.5) - cocoapods (1.1.1) + cocoapods (1.3.1) activesupport (>= 4.0.2, < 5) - claide (>= 1.0.1, < 2.0) - cocoapods-core (= 1.1.1) + claide (>= 1.0.2, < 2.0) + cocoapods-core (= 1.3.1) cocoapods-deintegrate (>= 1.0.1, < 2.0) - cocoapods-downloader (>= 1.1.2, < 2.0) + cocoapods-downloader (>= 1.1.3, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0) cocoapods-stats (>= 1.0.0, < 2.0) - cocoapods-trunk (>= 1.1.1, < 2.0) + cocoapods-trunk (>= 1.2.0, < 2.0) cocoapods-try (>= 1.1.0, < 2.0) - colored (~> 1.2) + colored2 (~> 3.1) escape (~> 0.0.4) fourflusher (~> 2.0.1) gh_inspector (~> 1.0) - molinillo (~> 0.5.1) + molinillo (~> 0.5.7) nap (~> 1.0) - xcodeproj (>= 1.3.3, < 2.0) - cocoapods-core (1.1.1) - activesupport (>= 4.0.2, < 5) + ruby-macho (~> 1.1) + xcodeproj (>= 1.5.1, < 2.0) + cocoapods-core (1.3.1) + activesupport (>= 4.0.2, < 6) fuzzy_match (~> 2.0.4) nap (~> 1.0) cocoapods-deintegrate (1.0.1) - cocoapods-downloader (1.1.2) - cocoapods-keys (1.7.0) + cocoapods-downloader (1.1.3) + cocoapods-keys (2.0.0) dotenv osx_keychain cocoapods-plugins (1.0.0) nap cocoapods-search (1.0.0) cocoapods-stats (1.0.0) - cocoapods-trunk (1.1.1) + cocoapods-trunk (1.3.0) nap (>= 0.8, < 2.0) - netrc (= 0.7.8) + netrc (~> 0.11) cocoapods-try (1.1.0) colored (1.2) - commander (4.4.3) + colored2 (3.1.2) + commander-fastlane (4.4.5) highline (~> 1.7.2) - credentials_manager (0.16.4) - colored - commander (>= 4.3.5) - highline (>= 1.7.1) - security - deliver (1.16.1) - credentials_manager (>= 0.16.2, < 1.0.0) - fastimage (~> 1.6) - fastlane_core (>= 0.58.0, < 1.0.0) - plist (>= 3.1.0, < 4.0.0) - spaceship (>= 0.38.5, < 1.0.0) - domain_name (0.5.20161129) + concurrent-ruby (1.0.5) + declarative (0.0.10) + declarative-option (0.1.0) + domain_name (0.5.20170404) unf (>= 0.0.5, < 1.0.0) - dotenv (2.1.1) + dotenv (2.2.1) escape (0.0.4) - excon (0.54.0) - faraday (0.10.0) + excon (0.59.0) + faraday (0.13.1) multipart-post (>= 1.2, < 3) faraday-cookie_jar (0.0.6) faraday (>= 0.7.4) http-cookie (~> 1.0.0) - faraday_middleware (0.10.1) + faraday_middleware (0.12.2) faraday (>= 0.7.4, < 1.0) - fastimage (1.6.8) - addressable (~> 2.3, >= 2.3.5) - fastlane (1.111.0) - activesupport (< 5) + fastimage (2.1.0) + fastlane (2.64.0) + CFPropertyList (>= 2.3, < 3.0.0) addressable (>= 2.3, < 3.0.0) - bundler (~> 1.12) - cert (>= 1.4.4, < 2.0.0) - credentials_manager (>= 0.16.2, < 1.0.0) - deliver (>= 1.15.1, < 2.0.0) - fastlane_core (>= 0.57.1, < 1.0.0) - frameit (>= 3.0.0, < 4.0.0) - gym (>= 1.12.1, < 2.0.0) - krausefx-shenzhen (>= 0.14.11, < 1.0.0) - match (>= 0.11.0, < 1.0.0) + babosa (>= 1.0.2, < 2.0.0) + bundler (>= 1.12.0, < 2.0.0) + colored + commander-fastlane (>= 4.4.5, < 5.0.0) + dotenv (>= 2.1.1, < 3.0.0) + excon (>= 0.45.0, < 1.0.0) + faraday (~> 0.9) + faraday-cookie_jar (~> 0.0.6) + faraday_middleware (~> 0.9) + fastimage (>= 2.1.0, < 3.0.0) + gh_inspector (>= 1.0.1, < 2.0.0) + google-api-client (>= 0.13.1, < 0.14.0) + highline (>= 1.7.2, < 2.0.0) + json (< 3.0.0) + mini_magick (~> 4.5.1) + multi_json + multi_xml (~> 0.5) multipart-post (~> 2.0.0) - pem (>= 1.4.0, < 2.0.0) - pilot (>= 1.12.1, < 2.0.0) plist (>= 3.1.0, < 4.0.0) - produce (>= 1.3.1, < 2.0.0) - scan (>= 0.14.2, < 1.0.0) - screengrab (>= 0.5.2, < 1.0.0) - sigh (>= 1.11.2, < 2.0.0) + public_suffix (~> 2.0.0) + rubyzip (>= 1.1.0, < 2.0.0) + security (= 0.1.3) slack-notifier (>= 1.3, < 2.0.0) - snapshot (>= 1.16.4, < 2.0.0) - spaceship (>= 0.38.1, < 1.0.0) - supply (>= 0.8.0, < 1.0.0) terminal-notifier (>= 1.6.2, < 2.0.0) terminal-table (>= 1.4.5, < 2.0.0) + tty-screen (~> 0.5.0) word_wrap (~> 1.0.0) - xcode-install (~> 2.0.0) - xcodeproj (>= 0.20, < 2.0.0) + xcodeproj (>= 1.5.0, < 2.0.0) xcpretty (>= 0.2.4, < 1.0.0) - fastlane_core (0.58.0) - colored - commander (>= 4.4.0, <= 5.0.0) - credentials_manager (>= 0.16.2, < 1.0.0) - excon (>= 0.45.0, < 1.0) - gh_inspector (>= 1.0.1, < 2.0.0) - highline (>= 1.7.2) - json - multi_json - plist (>= 3.1.0, < 4.0.0) - rubyzip (~> 1.1.6) - terminal-table (>= 1.4.5, < 2.0.0) + xcpretty-travis-formatter (>= 0.0.3) fourflusher (2.0.1) - frameit (3.0.0) - deliver (> 0.3) - fastimage (~> 1.6.3) - fastlane_core (>= 0.53.0, < 1.0.0) - mini_magick (~> 4.5.1) fuzzy_match (2.0.4) - gh_inspector (1.0.2) - google-api-client (0.9.20) - addressable (~> 2.3) + gh_inspector (1.0.3) + google-api-client (0.13.6) + addressable (~> 2.5, >= 2.5.1) googleauth (~> 0.5) - httpclient (~> 2.7) - hurley (~> 0.1) - memoist (~> 0.11) - mime-types (>= 1.6) - representable (~> 2.3.0) - retriable (~> 2.0) - googleauth (0.5.1) - faraday (~> 0.9) - jwt (~> 1.4) + httpclient (>= 2.8.1, < 3.0) + mime-types (~> 3.0) + representable (~> 3.0) + retriable (>= 2.0, < 4.0) + googleauth (0.6.1) + faraday (~> 0.12) + jwt (>= 1.4, < 3.0) logging (~> 2.0) memoist (~> 0.12) multi_json (~> 1.11) os (~> 0.9) signet (~> 0.7) - gym (1.12.1) - fastlane_core (>= 0.57.0, < 1.0.0) - plist (>= 3.1.0, < 4.0.0) - rubyzip (>= 1.1.7) - terminal-table (>= 1.4.5, < 2.0.0) - xcpretty (>= 0.2.4, < 1.0.0) highline (1.7.8) http-cookie (1.0.3) domain_name (~> 0.5) - httpclient (2.8.2.4) - hurley (0.2) - i18n (0.7.0) - json (1.8.3) - jwt (1.5.6) - krausefx-shenzhen (0.14.11) - commander (>= 4.3, < 5.0) - dotenv (>= 0.7) - faraday (~> 0.9) - faraday_middleware (~> 0.9) - highline (>= 1.7.2) - json (~> 1.8) - net-sftp (~> 2.1.2) - plist (>= 3.1.0, < 4.0.0) - rubyzip (~> 1.1) - security (~> 0.1.3) - terminal-table (~> 1.4.5) + httpclient (2.8.3) + i18n (0.9.1) + concurrent-ruby (~> 1.0) + json (2.1.0) + jwt (2.1.0) little-plugger (1.1.4) - logging (2.1.0) + logging (2.2.2) little-plugger (~> 1.1) multi_json (~> 1.10) - match (0.11.1) - cert (>= 1.4.4, < 2.0.0) - credentials_manager (>= 0.16.2, < 1.0.0) - fastlane_core (>= 0.58.0, < 1.0.0) - security - sigh (>= 1.12.1, < 2.0.0) - spaceship (>= 0.38.5, < 1.0.0) - memoist (0.15.0) + memoist (0.16.0) mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) mini_magick (4.5.1) mini_portile2 (2.1.0) - minitest (5.10.1) - molinillo (0.5.4) - multi_json (1.12.1) + minitest (5.10.3) + molinillo (0.5.7) + multi_json (1.12.2) multi_xml (0.6.0) multipart-post (2.0.0) nanaimo (0.2.3) nap (1.1.0) - net-sftp (2.1.2) - net-ssh (>= 2.6.5) - net-ssh (3.2.0) - netrc (0.7.8) + netrc (0.11.0) nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) os (0.9.6) osx_keychain (1.0.1) RubyInline (~> 3) - pem (1.4.1) - fastlane_core (>= 0.58.0, < 1.0.0) - spaceship (>= 0.38.5, < 1.0.0) - pilot (1.12.1) - credentials_manager (>= 0.16.0) - fastlane_core (>= 0.56.0, < 1.0.0) - spaceship (>= 0.37.0, < 1.0.0) - terminal-table (>= 1.4.5, < 2.0.0) - plist (3.2.0) - produce (1.3.2) - fastlane_core (>= 0.57.2, < 1.0.0) - spaceship (>= 0.38.4, < 1.0.0) - public_suffix (2.0.4) - representable (2.3.0) - uber (~> 0.0.7) - retriable (2.1.0) - rouge (1.11.1) - rubyzip (1.1.7) - scan (0.14.2) - fastlane_core (>= 0.57.0, < 1.0.0) - slack-notifier (~> 1.3) - terminal-table (>= 1.4.5, < 2.0.0) - xcpretty (>= 0.2.4, < 1.0.0) - xcpretty-travis-formatter (>= 0.0.3) - screengrab (0.5.6) - fastlane_core (>= 0.55.0, < 1.0.0) + plist (3.3.0) + public_suffix (2.0.5) + representable (3.0.4) + declarative (< 0.1.0) + declarative-option (< 0.2.0) + uber (< 0.2.0) + retriable (3.1.1) + rouge (2.0.7) + ruby-macho (1.1.0) + rubyzip (1.2.1) security (0.1.3) - sigh (1.12.1) - fastlane_core (>= 0.57.2, < 1.0.0) - plist (>= 3.1.0, < 4.0.0) - spaceship (>= 0.38.4, < 1.0.0) - signet (0.7.3) + signet (0.8.1) addressable (~> 2.3) faraday (~> 0.9) - jwt (~> 1.5) + jwt (>= 1.5, < 3.0) multi_json (~> 1.10) slack-notifier (1.5.1) - slather (2.3.0) + slather (2.4.3) + CFPropertyList (~> 2.2) activesupport (>= 4.0.2, < 5) clamp (~> 0.6) - nokogiri (~> 1.6.3) - xcodeproj (>= 0.20, < 2.0.0) - snapshot (1.16.4) - fastimage (~> 1.6.3) - fastlane_core (>= 0.57.0, < 1.0.0) - plist (>= 3.1.0, < 4.0.0) - xcpretty (>= 0.2.4, < 1.0.0) - spaceship (0.38.5) - babosa (= 1.0.2) - colored - credentials_manager (>= 0.16.0) - faraday (~> 0.9) - faraday-cookie_jar (~> 0.0.6) - faraday_middleware (~> 0.9) - fastimage (~> 1.6) - multi_xml (~> 0.5) - plist (>= 3.1.0, < 4.0.0) - supply (0.8.0) - credentials_manager (>= 0.16.0) - fastlane_core (>= 0.52.0) - google-api-client (~> 0.9.1) - terminal-notifier (1.7.1) - terminal-table (1.4.5) - thread_safe (0.3.5) - tzinfo (1.2.2) + nokogiri (>= 1.6, < 1.7) + xcodeproj (~> 1.4) + terminal-notifier (1.8.0) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) + thread_safe (0.3.6) + tty-screen (0.5.1) + tzinfo (1.2.4) thread_safe (~> 0.1) - uber (0.0.15) + uber (0.1.0) unf (0.1.4) unf_ext - unf_ext (0.0.7.2) + unf_ext (0.0.7.4) + unicode-display_width (1.3.0) word_wrap (1.0.0) - xcode-install (2.0.9) - claide (>= 0.9.1, < 1.1.0) - spaceship (>= 0.25.1, < 1.0.0) - xcodeproj (1.4.1) + xcodeproj (1.5.3) CFPropertyList (~> 2.3.3) - activesupport (>= 3) - claide (>= 1.0.1, < 2.0) - colored (~> 1.2) - nanaimo (~> 0.2.0) - xcpretty (0.2.4) - rouge (~> 1.8) - xcpretty-travis-formatter (0.0.4) + claide (>= 1.0.2, < 2.0) + colored2 (~> 3.1) + nanaimo (~> 0.2.3) + xcpretty (0.2.8) + rouge (~> 2.0.7) + xcpretty-travis-formatter (1.0.0) xcpretty (~> 0.2, >= 0.0.7) PLATFORMS @@ -299,10 +205,9 @@ PLATFORMS DEPENDENCIES cocoapods cocoapods-keys - credentials_manager (= 0.16.4) fastlane slather xcpretty BUNDLED WITH - 1.13.7 + 1.15.4 diff --git a/README.md b/README.md index d39f6ed..bfad29e 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ -![](https://raw.githubusercontent.com/JimRoepcke/RCSYapDatabaseExtensions/development/header.png) +![](https://raw.githubusercontent.com/danthorpe/YapDatabaseExtensions/development/header.png) -[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/RCSYapDatabaseExtensions.svg)](https://img.shields.io/cocoapods/v/RCSYapDatabaseExtensions.svg) -[![CocoaPods Documentation](https://img.shields.io/cocoapods/metrics/doc-percent/RCSYapDatabaseExtensions.svg?style=flat)](https://cocoapods.org/pods/RCSYapDatabaseExtensions) -[![Platform](https://img.shields.io/cocoapods/p/RCSYapDatabaseExtensions.svg?style=flat)](http://cocoadocs.org/docsets/RCSYapDatabaseExtensions) +[![Build status](https://badge.buildkite.com/95784c169af7db5e36cefe146d5d3f3899c8339d46096a6349.svg)](https://buildkite.com/danthorpe/yapdatabaseextensions?branch=development) +[![Coverage Status](https://coveralls.io/repos/github/danthorpe/YapDatabaseExtensions/badge.svg?branch=development)](https://coveralls.io/github/danthorpe/YapDatabaseExtensions?branch=development) +[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/YapDatabaseExtensions.svg)](https://img.shields.io/cocoapods/v/YapDatabaseExtensions.svg) +[![CocoaPods Documentation](https://img.shields.io/cocoapods/metrics/doc-percent/YapDatabaseExtensions.svg?style=flat)](https://cocoapods.org/pods/YapDatabaseExtensions) +[![Platform](https://img.shields.io/cocoapods/p/YapDatabaseExtensions.svg?style=flat)](http://cocoadocs.org/docsets/YapDatabaseExtensions) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) -# RCSYapDatabaseExtensions +# YapDatabaseExtensions -**This is a fork of Dan Thorpe's YapDatabaseExtensions. It was created as my client needed a Swift 3 version immediately, but it also has several other enhancements. Please see CHANGELOG.md for details.** +Read my introductory blog post about [YapDatabase & YapDatabaseExtensions](http://danthorpe.me/posts/yap-database.html), and a follow up on [YapDatabaseExtensions 2](http://danthorpe.me/posts/yapdatabaseextensions-two--the-swiftening.html). -Read Dan Thorpe's introductory blog post about [YapDatabase & YapDatabaseExtensions](http://danthorpe.me/posts/yap-database.html), and a follow up on [YapDatabaseExtensions 2](http://danthorpe.me/posts/yapdatabaseextensions-two--the-swiftening.html). - -RCSYapDatabaseExtensions is a suite of convenience APIs for working with [YapDatabase](https://github.com/yapstudios/YapDatabase). If you’re not familiar with YapDatabase, it’s a powerful key value database for iOS and Mac - [check it out](https://github.com/yapstudios/YapDatabase)! +YapDatabaseExtensions is a suite of convenience APIs for working with [YapDatabase](https://github.com/yapstudios/YapDatabase). If you’re not familiar with YapDatabase, it’s a powerful key value database for iOS and Mac - [check it out](https://github.com/yapstudios/YapDatabase)! ## Motivation While YapDatabase is great, it’s lacking some out of the box convenience and Swift support. In particular, YapDatabase works heavily with `AnyObject` types, which is fine for Objective-C but means no type fidelity with Swift. Similarly saving value types like structs or enums in YapDatabase is problematic. This framework has evolved through 2015 to tackle these issues. ## Value Types -The support for encoding and decoding value types, previously the `Saveable` and `Archiver` protocols, has been renamed and moved to their own project. [ValueCoding](https://github.com/danthorpe/ValueCoding) is a dependency of this framework (along with YapDatabase itself). See its [README](https://github.com/danthorpe/ValueCoding/blob/development/README.md) for more info. However, essentially, if you used this project before version 2.1, you’ll need to rename some types - and Xcode should present Fix It options. `Saveable` is now `ValueCoding`, its nested type, previously `ArchiverType` is now `Coder`, and this type must conform to a protocol, previously `Archiver`, now `CodingProtocol`. See how they were all mixed up? Now fixed. +The support for encoding and decoding value types, previously the `Saveable` and `Archiver` protocols, has been renamed and moved to their own project. [ValueCoding](https://github.com/danthorpe/ValueCoding) is a dependency of this framework (along with YapDatabase itself). See its [README](https://github.com/danthorpe/ValueCoding/blob/development/README.md) for more info. However, essentially, if you used this project before version 2.1, you’ll need to rename some types - and Xcode should present Fix It options. `Saveable` is now `ValueCoding`, its nested type, previously `ArchiverType` is now `Coder`, and this type must conform to a protocol, previously `Archiver`, now `CodingType`. See how they were all mixed up? Now fixed. ## `Persistable` This protocol expresses what is required to support reading from and writing to YapDatabase. Objects are referenced inside the database with a key (a `String`) inside a collection (also a `String`). @@ -30,8 +30,9 @@ public protocol Identifiable { public protocol Persistable: Identifiable { static var collection: String { get } + var metadata: MetadataType? { get set } } -``` +``` The `identifier` property allows the type to support an identifier type such as `NSUUID` or `Int`. @@ -40,13 +41,26 @@ While not a requirement of YapDatabase, for these extensions, it is required tha There is also a `YapDB.Index` struct which composes the key and collection into a single type. This is used internally for all access methods. Properties defined in an extension on `Persistable` provide access to `key` and `index`. ### Metadata -YapDatabase supports storing metadata alongside the primary object. RCSYapDatabaseExtensions supports optional reading and writing of metadata alongside a `Persistable` type. +YapDatabase supports storing metadata alongside the primary object. YapDatabaseExtensions supports automatic reading and writing of metadata as an optional property of the `Persistable` type. + +By default, all types which conform to `Persistable`, will get a `MetadataType` of `Void` which is synthesized by default. Therefore if you do not want or need a metadata type, there is nothing to do. + +To support a custom metadata type, just add the following to your `Persistable` type, e.g.: + +```swift +struct MyCustomValue: Persistable, ValueCoding { + typealias Coder = MyCustomValueCoder + static let collection = “MyCustomValues” + var metadata: MyCustomMetadata? = .None + let identifier: NSUUID +} +``` -Your custom metadata types must conform to either `NSCoding` or `ValueCoding`. +where the type (`MyCustomMetadata` in the above snippet) implements either `NSCoding` or `ValueCoding`. -**In this fork of YapDatabaseExtensions, metadata has been removed from `Persistable`, and all reads and writes of metadata must be done explicitly.** +When creating a new item, set the metadata property before saving the item to the database. YapDatabaseExtensions will then save the metadata inside YapDatabase correctly. *There is no need to encode the metadata inside the primary object*. When reading objects which have a valid `MetadataType`, YapDatabaseExtensions will automatically read, decode and set the item’s metadata before returning the item. -Additionally, since the `MetadataType` is decoupled from the `Persistable` type, a single `Persistable` type can use many different types of metadata, as appropriate. When you want to read or write a value and it's metadata together, you use the "withMetadata" variants of the API, which accept and return `YapItem` values. `YapItem` is basically a slightly nicer wrapper than a Swift tuple, which can be extended, unlike anonymous tuple types. +Note that previous metadata protocols `ObjectMetadataPersistable` and `ValueMetadataPersistable` have been deprecated in favor of `Persistable`. ## “Correct” Type Patterns Because the generic protocols, `ValueCoding` and `CodingType` have self-reflective properties, they must be correctly implemented for the APIs to be available. This means that the equality `ValueCoding.Coder.ValueType == Self` must be met. The APIs are all composed with this represented in their generic where clauses. This means that if your `ValueCoding` type is not the `ValueType` of its `Coder`, your code will not compile. @@ -55,16 +69,16 @@ Therefore, there are six valid `Persistable` type patterns as described in the t Item encoding | Metadata encoding | Pattern --------------|-------------------|------------------ -`NSCoding` | No Metadata | Object +`NSCoding` | `Void` Metadata | Object `NSCoding` | `NSCoding` | ObjectWithObjectMetadata `NSCoding` | `ValueCoding` | ObjectWithValueMetadata -`ValueCoding` | No Metadata | Value +`ValueCoding` | `Void` Metadata | Value `ValueCoding` | `NSCoding` | ValueWithObjectMetadata `ValueCoding` | `ValueCoding` | ValueWithValueMetadata ## Extension APIs -RCSYapDatabaseExtensions provides two styles of API. The *functional* API works on `YapDatabase` types, `YapDatabaseReadTransaction`, `YapDatabaseReadWriteTransaction` and `YapDatabaseConnection`. The *persistable* API works on your `Persistable` types directly, and receives the `YapDatabase` type as arguments. +YapDatabaseExtensions provides two styles of API. The *functional* API works on `YapDatabase` types, `YapDatabaseReadTransaction`, `YapDatabaseReadWriteTransaction` and `YapDatabaseConnection`. The *persistable* API works on your `Persistable` types directly, and receives the `YapDatabase` type as arguments. ### Functional API @@ -75,7 +89,7 @@ The following “functional” APIs are available directly on the `YapDatabase` let connection = db.newConnection() // Write a single item -connection.write(item) +connection.write(item) // Write an array of items, using one transaction. connection.write(items) @@ -87,13 +101,13 @@ connection.asyncWrite(items) { print(“did finish writing”) } // Create a write transaction block for multiple writes. connection.write { transaction in transaction.write(item) - transaction.write(items) + transaction.write(items) } // Write many items asynchronously connection.asyncWrite({ transaction in transaction.write(item) - transaction.write(items) + transaction.write(items) }, completion: { print(“did finish writing”) }) ``` @@ -104,7 +118,7 @@ if let item: Item? = connection.readAtIndex(index) { // etc } -if let meta: MetadataType? = connection.readMetadataAtIndex(index) { +if let meta: Item.MetadataType? = connection.readMetadataAtIndex(index) { // etc } @@ -124,7 +138,7 @@ connection.read { transaction in let c: [Item] = transaction.readAtIndexes(indexes) let d: [Item] = transaction.readByKeys(keys) let all: [Item] = transaction.readAll() - let meta: [MetadataType] = transaction.readMetadataAtIndexes(indexes) + let meta: [Item.MetadataType] = transaction.readMetadataAtIndexes(indexes) } ``` @@ -146,23 +160,16 @@ item.asyncWrite(connection) { written in // Return an NSOperation which will perform an sync write on a YapDatabaseConnection. let write: NSOperation = item.write(connection) -``` +``` Reading items from the database is a little different. ```swift // Read using a YapDB.Index. -if let item = Item.read(transaction).atIndex(index) { +if let item = Item.read(transaction).byIndex(index) { // etc - item is correct type, no casting required. } -// Read value and metadata using a YapDB.Index. -if let item: YapItem? = Item.read(transaction).withMetadataAtIndex(index) { - // etc - item is a correct type, no casting required. - // item.value contains the value - // item.metadata contains the metadata, wrapped in an Optional -} - // Read an array of items from an array of YapDB.Index(s) let items = Item.read(transaction).atIndexes(indexes) @@ -180,12 +187,12 @@ if let allItems = Item.read(transaction).all() { // Get the Items which exist for the given keys, and return the [String] keys which are missing. let (items, missingKeys) = Item.read(transaction).filterExisting(someKeys) -``` +``` Similarly, to work directly on a `YapDatabaseConnection`, use the following: ```swift -if let item = Item.read(connection).atIndex(index) { +if let item = Item.read(connection).byIndex(index) { // etc - item is correct type, no casting required. } @@ -202,22 +209,22 @@ let (items, missingKeys) = Item.read(connection).filterExisting(someKeys) ## Installation -RCSYapDatabaseExtensions is available through [CocoaPods](http://cocoapods.org). To install +YapDatabaseExtensions is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile: ```ruby -pod 'RCSYapDatabaseExtensions' +pod 'YapDatabaseExtensions' ``` If you don’t want the extensions API on `Persistable`, integrate the Functional subspec like this: ```ruby -pod 'RCSYapDatabaseExtensions/Functional’ +pod 'YapDatabaseExtensions/Functional’ ``` ## API Documentation -API documentation is available on [CocoaDocs.org](http://cocoadocs.org/docsets/RCSYapDatabaseExtensions). +API documentation is available on [CocoaDocs.org](http://cocoadocs.org/docsets/YapDatabaseExtensions). ## Developing @@ -226,8 +233,7 @@ To start working in this repository’s `YapDatabaseExtensions.xcodeproj`, you ## Author Daniel Thorpe, [@danthorpe](https://twitter.com/danthorpe) -Jim Roepcke, [@JimRoepcke](https://twitter.com/JimRoepcke) ## License -RCSYapDatabaseExtensions is available under the MIT license. See the LICENSE file for more info. +YapDatabaseExtensions is available under the MIT license. See the LICENSE file for more info. diff --git a/RCSYapDatabaseExtensions.podspec b/YapDatabaseExtensions.podspec similarity index 58% rename from RCSYapDatabaseExtensions.podspec rename to YapDatabaseExtensions.podspec index 6bfe393..c0f4f36 100644 --- a/RCSYapDatabaseExtensions.podspec +++ b/YapDatabaseExtensions.podspec @@ -1,48 +1,44 @@ Pod::Spec.new do |s| - s.name = "RCSYapDatabaseExtensions" - s.version = "3.0.1" + s.name = "YapDatabaseExtensions" + s.version = "4.0.0" s.summary = "Helpers for using value types with YapDatabase." s.description = <<-DESC - + Defines APIs to conveniently read, write and remove objects and values to or from YapDatabse. See ValueCoding for value type support. - - Fork of danthorpe's YapDatabaseExtensions with Swift 3 support and - metadata separated from objects. DESC s.homepage = "https://github.com/JimRoepcke/YapDatabaseExtensions" s.license = 'MIT' s.authors = { "Daniel Thorpe" => "@danthorpe", "Jim Roepcke" => "@JimRoepcke" } - s.source = { :git => "https://github.com/JimRoepcke/YapDatabaseExtensions.git", :tag => s.version.to_s } - s.module_name = 'RCSYapDatabaseExtensions' - s.social_media_url = 'https://twitter.com/JimRoepcke' + s.source = { :git => "https://github.com/danthorpe/YapDatabaseExtensions.git", :tag => s.version.to_s } + s.module_name = 'YapDatabaseExtensions' + s.social_media_url = 'https://twitter.com/danthorpe' s.requires_arc = true s.default_subspec = 'Persitable' s.ios.deployment_target = '9.0' s.osx.deployment_target = '10.11' - s.dependency 'ValueCoding', '~> 2.1.0' - s.dependency 'YapDatabase', '~> 2.9.2' - + s.dependency 'ValueCoding', '~> 3.0.0' + s.dependency 'YapDatabase', '~> 3.0.0' + s.subspec 'Core' do |ss| ss.source_files = [ 'Sources/YapDatabaseExtensions.swift', - 'Sources/YapDB.swift' + 'Sources/YapDB.swift' ] end - + s.subspec 'Functional' do |ss| - ss.dependency 'RCSYapDatabaseExtensions/Core' + ss.dependency 'YapDatabaseExtensions/Core' ss.source_files = 'Sources/Functional_*.swift' end s.subspec 'Persitable' do |ss| - ss.dependency 'RCSYapDatabaseExtensions/Functional' + ss.dependency 'YapDatabaseExtensions/Functional' ss.source_files = [ - 'Sources/Read.swift', + 'Sources/Read.swift', 'Sources/Persistable_*.swift' ] end end -