diff --git a/.gitignore b/.gitignore index 9442cfe..14520d6 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ xcuserdata *.xcuserstate *.xcscmblueprint XcodeDevelopment/ +*.DS_Store diff --git a/Package.swift b/Package.swift index d15f864..1f2b41a 100644 --- a/Package.swift +++ b/Package.swift @@ -1,7 +1,7 @@ import PackageDescription let package = Package( - name: "StructuredDataMapper", + name: "Mapper", dependencies: [ .Package(url: "https://github.com/Zewo/InterchangeData.git", majorVersion: 0, minor: 4) ] diff --git a/Sources/Mappable.swift b/Sources/Mappable.swift index 740c223..008312d 100644 --- a/Sources/Mappable.swift +++ b/Sources/Mappable.swift @@ -25,19 +25,21 @@ @_exported import StructuredData public protocol Mappable: StructuredDataInitializable { - init(map: Mapper) throws + + init(mapper: Mapper) throws + } extension Mappable { public init(structuredData: StructuredData) throws { - try self.init(map: structuredData.mapper) + try self.init(mapper: structuredData.mapper) } } extension Mappable { public static func makeWith(structuredData structuredData: StructuredData) -> Self? { do { - return try self.init(map: structuredData.mapper) + return try self.init(mapper: structuredData.mapper) } catch { return nil } diff --git a/Sources/Mapper.swift b/Sources/Mapper.swift index 8c9faab..d42bb96 100644 --- a/Sources/Mapper.swift +++ b/Sources/Mapper.swift @@ -29,6 +29,7 @@ public final class Mapper { public enum Error: ErrorProtocol { case cantInitFromRawValue case noInterchangeData(key: String) + case incompatibleSequence } public init(structuredData: StructuredData) { @@ -41,19 +42,19 @@ public final class Mapper { // MARK: - General case extension Mapper { - public func from(key: String) throws -> T { + public func map(from key: String) throws -> T { let value: T = try structuredData.get(key) return value } - public func from(key: String) throws -> T { + public func map(from key: String) throws -> T { if let nested = structuredData[key] { return try unwrap(T(structuredData: nested)) } throw Error.noInterchangeData(key: key) } - public func from(key: String) throws -> T { + public func map(from key: String) throws -> T { guard let rawValue = try structuredData[key].flatMap({ try T.RawValue(structuredData: $0) }) else { throw Error.cantInitFromRawValue } @@ -67,29 +68,19 @@ extension Mapper { // MARK: - Arrays extension Mapper { - public func arrayFrom(key: String) throws -> [T] { - return try structuredData.flatMapThrough(key) { - do { - let some: T = try $0.get() - return some - } catch { - return nil - } - } + + public func map(arrayFrom key: String) throws -> [T] { + return try structuredData.flatMapThrough(key) { try $0.get() as T } } - public func arrayFrom(key: String) throws -> [T] { + public func map(arrayFrom key: String) throws -> [T] { return try structuredData.flatMapThrough(key) { try? T(structuredData: $0) } } - public func arrayFrom(key: String) throws -> [T] { + public func map(arrayFrom key: String) throws -> [T] { return try structuredData.flatMapThrough(key) { - do { - let rawValue = try T.RawValue(structuredData: $0) - return T(rawValue: rawValue) - } catch { - return nil - } + return (try? T.RawValue(structuredData: $0)).flatMap({ T(rawValue: $0) }) } } } @@ -97,22 +88,23 @@ extension Mapper { // MARK: - Optionals extension Mapper { - public func optionalFrom(key: String) -> T? { + + public func map(optionalFrom key: String) -> T? { do { - return try from(key) + return try map(from: key) } catch { return nil } } - public func optionalFrom(key: String) -> T? { + public func map(optionalFrom key: String) -> T? { if let nested = structuredData[key] { return try? T(structuredData: nested) } return nil } - public func optionalFrom(key: String) -> T? { + public func map(optionalFrom key: String) -> T? { do { if let rawValue = try structuredData[key].flatMap({ try T.RawValue(structuredData: $0) }), value = T(rawValue: rawValue) { @@ -128,44 +120,19 @@ extension Mapper { // MARK: - Optional arrays extension Mapper { - public func optionalArrayFrom(key: String) -> [T]? { - do { - let inter: [StructuredData] = try structuredData.get(key) - return inter.flatMap { - do { - let some: T = try $0.get() - return some - } catch { - return nil - } - } - } catch { - return nil - } + + public func map(optionalArrayFrom key: String) -> [T]? { + return try? structuredData.flatMapThrough(key) { try $0.get() as T } } - public func optionalArrayFrom(key: String) -> [T]? { - do { - let inter: [StructuredData] = try structuredData.get(key) - return inter.flatMap({ try? T(structuredData: $0) }) - } catch { - return nil - } + public func map(optionalArrayFrom key: String) -> [T]? { + return try? structuredData.flatMapThrough(key) { try? T(structuredData: $0) } } - public func optionalArrayFrom(key: String) -> [T]? { - do { - let inter: [StructuredData] = try structuredData.get(key) - return inter.flatMap { - do { - let rawValue = try T.RawValue(structuredData: $0) - return T(rawValue: rawValue) - } catch { - return nil - } - } - } catch { - return nil + public func map(optionalArrayFrom key: String) -> [T]? { + return try? structuredData.flatMapThrough(key) { + return (try? T.RawValue(structuredData: $0)).flatMap({ T(rawValue: $0) }) } } } diff --git a/Tests/Mapper/MappableValueTests.swift b/Tests/Mapper/MappableValueTests.swift index 24c7e62..adda694 100644 --- a/Tests/Mapper/MappableValueTests.swift +++ b/Tests/Mapper/MappableValueTests.swift @@ -46,91 +46,91 @@ class MappableValueTests: XCTestCase { func testNestedMappable() { struct Test: Mappable { let nest: Nested - init(map: Mapper) throws { - try self.nest = map.from("nest") + init(mapper: Mapper) throws { + try self.nest = mapper.map(from: "nest") } } struct Nested: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("string") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "string") } } let structuredData: StructuredData = [ "nest": ["string": "hello"] ] - let test = try! Test(map: Mapper(structuredData: structuredData)) + let test = try! Test(mapper: Mapper(structuredData: structuredData)) XCTAssertEqual(test.nest.string, "hello") } func testNestedInvalidMappable() { struct Nested: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("string") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "string") } } struct Test: Mappable { let nested: Nested - init(map: Mapper) throws { - try self.nested = map.from("nest") + init(mapper: Mapper) throws { + try self.nested = mapper.map(from: "nest") } } let structuredData: StructuredData = ["nest": ["strong": "er"]] - let test = try? Test(map: Mapper(structuredData: structuredData)) + let test = try? Test(mapper: Mapper(structuredData: structuredData)) XCTAssertNil(test) } func testNestedOptionalMappable() { struct Nested: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("string") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "string") } } struct Test: Mappable { let nested: Nested? - init(map: Mapper) throws { - self.nested = map.optionalFrom("nest") + init(mapper: Mapper) throws { + self.nested = mapper.map(optionalFrom: "nest") } } let structuredData: StructuredData = ["nest": ["string": "zewo"]] - let test = try! Test(map: Mapper(structuredData: structuredData)) + let test = try! Test(mapper: Mapper(structuredData: structuredData)) XCTAssertEqual(test.nested!.string, "zewo") } func testNestedOptionalInvalidMappable() { struct Nested: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("string") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "string") } } struct Test: Mappable { let nested: Nested? - init(map: Mapper) throws { - self.nested = map.optionalFrom("nest") + init(mapper: Mapper) throws { + self.nested = mapper.map(optionalFrom: "nest") } } let structuredData: StructuredData = ["nest": ["strong": "er"]] - let test = try! Test(map: Mapper(structuredData: structuredData)) + let test = try! Test(mapper: Mapper(structuredData: structuredData)) XCTAssertNil(test.nested) } func testArrayOfMappables() { struct Nested: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("string") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "string") } } struct Test: Mappable { let nested: [Nested] - init(map: Mapper) throws { - try self.nested = map.arrayFrom("nested") + init(mapper: Mapper) throws { + try self.nested = mapper.map(arrayFrom: "nested") } } - let test = try! Test(map: Mapper(structuredData: ["nested": [["string": "fire"], ["string": "sun"]]])) + let test = try! Test(mapper: Mapper(structuredData: ["nested": [["string": "fire"], ["string": "sun"]]])) XCTAssertEqual(test.nested.count, 2) XCTAssertEqual(test.nested[1].string, "sun") } @@ -138,119 +138,119 @@ class MappableValueTests: XCTestCase { func testArrayOfInvalidMappables() { struct Nested: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("string") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "string") } } struct Test: Mappable { let nested: [Nested] - init(map: Mapper) throws { - try self.nested = map.arrayFrom("nested") + init(mapper: Mapper) throws { + try self.nested = mapper.map(arrayFrom: "nested") } } - let test = try! Test(map: Mapper(structuredData: ["nested": [["string": 1], ["string": 1]]])) + let test = try! Test(mapper: Mapper(structuredData: ["nested": [["string": 1], ["string": 1]]])) XCTAssertTrue(test.nested.isEmpty) } func testInvalidArrayOfMappables() { struct Nested: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("string") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "string") } } struct Test: Mappable { let nested: [Nested] - init(map: Mapper) throws { - try self.nested = map.arrayFrom("nested") + init(mapper: Mapper) throws { + try self.nested = mapper.map(arrayFrom: "nested") } } - let test = try? Test(map: Mapper(structuredData: ["hested": [["strong": "fire"], ["strong": "sun"]]])) + let test = try? Test(mapper: Mapper(structuredData: ["hested": [["strong": "fire"], ["strong": "sun"]]])) XCTAssertNil(test) } func testArrayOfPartiallyInvalidMappables() { struct Nested: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("string") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "string") } } struct Test: Mappable { let nested: [Nested] - init(map: Mapper) throws { - try self.nested = map.arrayFrom("nested") + init(mapper: Mapper) throws { + try self.nested = mapper.map(arrayFrom: "nested") } } - let test = try! Test(map: Mapper(structuredData: ["nested": [["string": 1], ["string": "fire"]]])) + let test = try! Test(mapper: Mapper(structuredData: ["nested": [["string": 1], ["string": "fire"]]])) XCTAssertEqual(test.nested.count, 1) } func testExistingOptionalArrayOfMappables() { struct Nested: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("string") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "string") } } struct Test: Mappable { let nested: [Nested]? - init(map: Mapper) throws { - self.nested = map.optionalArrayFrom("nested") + init(mapper: Mapper) throws { + self.nested = mapper.map(optionalArrayFrom: "nested") } } - let test = try! Test(map: Mapper(structuredData: ["nested": [["string": "ring"], ["string": "fire"]]])) + let test = try! Test(mapper: Mapper(structuredData: ["nested": [["string": "ring"], ["string": "fire"]]])) XCTAssertEqual(test.nested!.count, 2) } func testOptionalArrayOfMappables() { struct Nested: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("string") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "string") } } struct Test: Mappable { let nested: [Nested]? - init(map: Mapper) throws { - self.nested = map.optionalArrayFrom("nested") + init(mapper: Mapper) throws { + self.nested = mapper.map(optionalArrayFrom: "nested") } } - let test = try! Test(map: Mapper(structuredData: [])) + let test = try! Test(mapper: Mapper(structuredData: [])) XCTAssertNil(test.nested) } func testOptionalArrayOfInvalidMappables() { struct Nested: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("string") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "string") } } struct Test: Mappable { let nested: [Nested]? - init(map: Mapper) throws { - self.nested = map.optionalArrayFrom("nested") + init(mapper: Mapper) throws { + self.nested = mapper.map(optionalArrayFrom: "nested") } } - let test = try! Test(map: Mapper(structuredData: ["nested": [["strong": 3], ["strong": 5]]])) + let test = try! Test(mapper: Mapper(structuredData: ["nested": [["strong": 3], ["strong": 5]]])) XCTAssertTrue(test.nested!.isEmpty) } func testOptionalArrayOfPartiallyInvalidMappables() { struct Nested: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("string") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "string") } } struct Test: Mappable { let nested: [Nested]? - init(map: Mapper) throws { - self.nested = map.optionalArrayFrom("nested") + init(mapper: Mapper) throws { + self.nested = mapper.map(optionalArrayFrom: "nested") } } - let test = try! Test(map: Mapper(structuredData: ["nested": [["string": 1], ["string": "fire"]]])) + let test = try! Test(mapper: Mapper(structuredData: ["nested": [["string": 1], ["string": "fire"]]])) XCTAssertEqual(test.nested!.count, 1) } } diff --git a/Tests/Mapper/NormalValueTests.swift b/Tests/Mapper/NormalValueTests.swift index b077b57..9545d3c 100644 --- a/Tests/Mapper/NormalValueTests.swift +++ b/Tests/Mapper/NormalValueTests.swift @@ -39,58 +39,58 @@ class NormalValueTests: XCTestCase { func testMappingString() { struct Test: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("string") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "string") } } - let test = try! Test(map: Mapper(structuredData: ["string": "Hello"])) + let test = try! Test(mapper: Mapper(structuredData: ["string": "Hello"])) XCTAssertTrue(test.string == "Hello") } func testMappingMissingKey() { struct Test: Mappable { let string: String - init(map: Mapper) throws { - try self.string = map.from("foo") + init(mapper: Mapper) throws { + try self.string = mapper.map(from: "foo") } } - let test = try? Test(map: Mapper(structuredData: [:])) + let test = try? Test(mapper: Mapper(structuredData: [:])) XCTAssertNil(test) } func testFallbackMissingKey() { struct Test: Mappable { let string: String - init(map: Mapper) throws { - self.string = map.optionalFrom("foo") ?? "Hello" + init(mapper: Mapper) throws { + self.string = mapper.map(optionalFrom: "foo") ?? "Hello" } } - let test = try! Test(map: Mapper(structuredData: [:])) + let test = try! Test(mapper: Mapper(structuredData: [:])) XCTAssertTrue(test.string == "Hello") } func testArrayOfStrings() { struct Test: Mappable { let strings: [String] - init(map: Mapper) throws { - try self.strings = map.arrayFrom("strings") + init(mapper: Mapper) throws { + try self.strings = mapper.map(arrayFrom: "strings") } } - let test = try! Test(map: Mapper(structuredData: ["strings": ["first", "second"]])) + let test = try! Test(mapper: Mapper(structuredData: ["strings": ["first", "second"]])) XCTAssertEqual(test.strings.count, 2) } func testPartiallyInvalidArrayOfValues() { struct Test: Mappable { let strings: [String] - init(map: Mapper) throws { - try self.strings = map.arrayFrom("strings") + init(mapper: Mapper) throws { + try self.strings = mapper.map(arrayFrom: "strings") } } - let test = try! Test(map: Mapper(structuredData: ["strings": ["first", "second", 3]])) + let test = try! Test(mapper: Mapper(structuredData: ["strings": ["first", "second", 3]])) XCTAssertEqual(test.strings.count, 2) } } diff --git a/Tests/Mapper/OptionalValueTests.swift b/Tests/Mapper/OptionalValueTests.swift index 98a3644..f02c558 100644 --- a/Tests/Mapper/OptionalValueTests.swift +++ b/Tests/Mapper/OptionalValueTests.swift @@ -39,55 +39,55 @@ final class OptionalValueTests: XCTestCase { func testMappingToClass() { final class Test: Mappable { let string: String - required init(map: Mapper) throws { - self.string = map.optionalFrom("string") ?? "" + required init(mapper: Mapper) throws { + self.string = mapper.map(optionalFrom: "string") ?? "" } } - let test = try! Test(map: Mapper(structuredData: ["string": "Hello"])) + let test = try! Test(mapper: Mapper(structuredData: ["string": "Hello"])) XCTAssertEqual(test.string, "Hello") } func testMappingOptionalValue() { struct Test: Mappable { let string: String? - init(map: Mapper) throws { - self.string = map.optionalFrom("whiskey") + init(mapper: Mapper) throws { + self.string = mapper.map(optionalFrom: "whiskey") } } - let test = try! Test(map: Mapper(structuredData: .nullValue)) + let test = try! Test(mapper: Mapper(structuredData: .nullValue)) XCTAssertNil(test.string) } func testMappingOptionalExisitngValue() { struct Test: Mappable { let string: String? - init(map: Mapper) throws { - string = map.optionalFrom("whiskey") + init(mapper: Mapper) throws { + string = mapper.map(optionalFrom: "whiskey") } } - let test = try! Test(map: Mapper(structuredData: ["whiskey": "flows"])) + let test = try! Test(mapper: Mapper(structuredData: ["whiskey": "flows"])) XCTAssertEqual(test.string, "flows") } func testMappingOptionalArray() { struct Test: Mappable { let strings: [String]? - init(map: Mapper) throws { - self.strings = map.optionalArrayFrom("whiskey") + init(mapper: Mapper) throws { + self.strings = mapper.map(optionalArrayFrom: "whiskey") } } - let test = try! Test(map: Mapper(structuredData: .nullValue)) + let test = try! Test(mapper: Mapper(structuredData: .nullValue)) XCTAssertNil(test.strings) } func testMappingOptionalExistingArray() { struct Test: Mappable { let strings: [String]? - init(map: Mapper) throws { - self.strings = map.optionalArrayFrom("whiskey") + init(mapper: Mapper) throws { + self.strings = mapper.map(optionalArrayFrom: "whiskey") } } - let test = try! Test(map: Mapper(structuredData: ["whiskey": ["lera", "lynn"]])) + let test = try! Test(mapper: Mapper(structuredData: ["whiskey": ["lera", "lynn"]])) XCTAssertEqual(test.strings!, ["lera", "lynn"]) } } diff --git a/Tests/Mapper/RawRepresentableValueTests.swift b/Tests/Mapper/RawRepresentableValueTests.swift index 3d15324..7397a20 100644 --- a/Tests/Mapper/RawRepresentableValueTests.swift +++ b/Tests/Mapper/RawRepresentableValueTests.swift @@ -49,11 +49,11 @@ class RawRepresentableValueTests: XCTestCase { } struct Test: Mappable { let suit: Suits - init(map: Mapper) throws { - try self.suit = map.from("suit") + init(mapper: Mapper) throws { + try self.suit = mapper.map(from: "suit") } } - let test = try! Test(map: Mapper(structuredData: ["suit": "barney"])) + let test = try! Test(mapper: Mapper(structuredData: ["suit": "barney"])) XCTAssertEqual(test.suit, Suits.Barney) } @@ -63,11 +63,11 @@ class RawRepresentableValueTests: XCTestCase { } struct Test: Mappable { let value: Value - init(map: Mapper) throws { - try self.value = map.from("value") + init(mapper: Mapper) throws { + try self.value = mapper.map(from: "value") } } - let test = try! Test(map: Mapper(structuredData: ["value": 1.0])) + let test = try! Test(mapper: Mapper(structuredData: ["value": 1.0])) XCTAssertEqual(test.value, Value.first) } @@ -77,11 +77,11 @@ class RawRepresentableValueTests: XCTestCase { } struct Test: Mappable { let value: Value - init(map: Mapper) throws { - try self.value = map.from("value") + init(mapper: Mapper) throws { + try self.value = mapper.map(from: "value") } } - let test = try! Test(map: Mapper(structuredData: ["value": 1])) + let test = try! Test(mapper: Mapper(structuredData: ["value": 1])) XCTAssertEqual(test.value, Value.first) } @@ -91,11 +91,11 @@ class RawRepresentableValueTests: XCTestCase { } struct Test: Mappable { let value: Value - init(map: Mapper) throws { - try self.value = map.from("value") + init(mapper: Mapper) throws { + try self.value = mapper.map(from: "value") } } - let test = try? Test(map: Mapper(structuredData: .nullValue)) + let test = try? Test(mapper: Mapper(structuredData: .nullValue)) XCTAssertNil(test) } @@ -105,11 +105,11 @@ class RawRepresentableValueTests: XCTestCase { } struct Test: Mappable { let value: Value? - init(map: Mapper) throws { - self.value = map.optionalFrom("value") + init(mapper: Mapper) throws { + self.value = mapper.map(optionalFrom: "value") } } - let test = try! Test(map: Mapper(structuredData: .nullValue)) + let test = try! Test(mapper: Mapper(structuredData: .nullValue)) XCTAssertNil(test.value) } @@ -119,11 +119,11 @@ class RawRepresentableValueTests: XCTestCase { } struct Test: Mappable { let value: Value? - init(map: Mapper) throws { - self.value = map.optionalFrom("value") + init(mapper: Mapper) throws { + self.value = mapper.map(optionalFrom: "value") } } - let test = try! Test(map: Mapper(structuredData: ["value": 1.0])) + let test = try! Test(mapper: Mapper(structuredData: ["value": 1.0])) XCTAssertEqual(test.value, Value.First) } @@ -133,11 +133,11 @@ class RawRepresentableValueTests: XCTestCase { } struct Test: Mappable { let value: Value? - init(map: Mapper) throws { - self.value = map.optionalFrom("value") + init(mapper: Mapper) throws { + self.value = mapper.map(optionalFrom: "value") } } - let test = try! Test(map: Mapper(structuredData: ["value": "cike"])) + let test = try! Test(mapper: Mapper(structuredData: ["value": "cike"])) XCTAssertNil(test.value) } @@ -147,12 +147,12 @@ class RawRepresentableValueTests: XCTestCase { } struct Test: Mappable { let barneys: [Barney] - init(map: Mapper) throws { - try self.barneys = map.arrayFrom("barneys") + init(mapper: Mapper) throws { + try self.barneys = mapper.map(arrayFrom: "barneys") } } let barneysContent: StructuredData = ["barneys": ["legendary", "stinson", "awesome"]] - let test = try! Test(map: Mapper(structuredData: barneysContent)) + let test = try! Test(mapper: Mapper(structuredData: barneysContent)) XCTAssertEqual(test.barneys, [Barney.legendary, Barney.stinson, Barney.awesome]) } @@ -162,12 +162,12 @@ class RawRepresentableValueTests: XCTestCase { } struct Test: Mappable { let barneys: [Barney] - init(map: Mapper) throws { - try self.barneys = map.arrayFrom("barneys") + init(mapper: Mapper) throws { + try self.barneys = mapper.map(arrayFrom: "barneys") } } let barneysContent: StructuredData = ["barneys": ["legendary", "stinson", "captain"]] - let test = try! Test(map: Mapper(structuredData: barneysContent)) + let test = try! Test(mapper: Mapper(structuredData: barneysContent)) XCTAssertEqual(test.barneys, [Barney.legendary, Barney.stinson]) } @@ -177,11 +177,11 @@ class RawRepresentableValueTests: XCTestCase { } struct Test: Mappable { let barneys: [Barney]? - init(map: Mapper) throws { - self.barneys = map.optionalArrayFrom("barneys") + init(mapper: Mapper) throws { + self.barneys = mapper.map(optionalArrayFrom: "barneys") } } - let test = try! Test(map: Mapper(structuredData: .nullValue)) + let test = try! Test(mapper: Mapper(structuredData: .nullValue)) XCTAssertNil(test.barneys) } @@ -191,12 +191,12 @@ class RawRepresentableValueTests: XCTestCase { } struct Test: Mappable { let barneys: [Barney]? - init(map: Mapper) throws { - self.barneys = map.optionalArrayFrom("barneys") + init(mapper: Mapper) throws { + self.barneys = mapper.map(optionalArrayFrom: "barneys") } } let barneysContent: StructuredData = ["barneys": ["legendary", "stinson", "awesome"]] - let test = try! Test(map: Mapper(structuredData: barneysContent)) + let test = try! Test(mapper: Mapper(structuredData: barneysContent)) XCTAssertEqual(test.barneys!, [Barney.legendary, Barney.stinson, Barney.awesome]) } }