From 11e8d13f020e5e61e6c3a9975890f991dbaa804e Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Tue, 8 Jan 2019 20:47:12 -0800 Subject: [PATCH 1/5] Switch package to swift 5, fix warnings. --- Package.swift | 2 +- .../JSONAPI/Resource/Attribute+Functor.swift | 4 +-- Sources/JSONAPI/Resource/Entity.swift | 28 +++++++++---------- Sources/JSONAPITestLib/EntityCheck.swift | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Package.swift b/Package.swift index 7adbb9b..6fdb92d 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.2 +// swift-tools-version:5.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription diff --git a/Sources/JSONAPI/Resource/Attribute+Functor.swift b/Sources/JSONAPI/Resource/Attribute+Functor.swift index e914e2e..1da6ff0 100644 --- a/Sources/JSONAPI/Resource/Attribute+Functor.swift +++ b/Sources/JSONAPI/Resource/Attribute+Functor.swift @@ -15,7 +15,7 @@ public extension TransformedAttribute { /// Generally, this is the most useful operation. The transformer gives you /// control over the decoding of the Attribute, but once the Attribute exists, /// mapping on it is most useful for creating computed Attribute properties. - public func map(_ transform: (Transformer.To) throws -> T) rethrows -> Attribute { + func map(_ transform: (Transformer.To) throws -> T) rethrows -> Attribute { return Attribute(value: try transform(value)) } } @@ -30,7 +30,7 @@ public extension Attribute { /// Generally, this is the most useful operation. The transformer gives you /// control over the decoding of the Attribute, but once the Attribute exists, /// mapping on it is most useful for creating computed Attribute properties. - public func map(_ transform: (ValueType) throws -> T) rethrows -> Attribute { + func map(_ transform: (ValueType) throws -> T) rethrows -> Attribute { return Attribute(value: try transform(value)) } } diff --git a/Sources/JSONAPI/Resource/Entity.swift b/Sources/JSONAPI/Resource/Entity.swift index 6d6da14..22f16fe 100644 --- a/Sources/JSONAPI/Resource/Entity.swift +++ b/Sources/JSONAPI/Resource/Entity.swift @@ -397,20 +397,20 @@ public extension Entity where EntityRawIdType: JSONAPI.RawIdType { /// An Entity.Pointer is a `ToOneRelationship` with no metadata or links. /// This is just a convenient way to reference an Entity so that /// other Entities' Relationships can be built up from it. - public typealias Pointer = ToOneRelationship + typealias Pointer = ToOneRelationship /// Entity.Pointers is a `ToManyRelationship` with no metadata or links. /// This is just a convenient way to reference a bunch of Entities so /// that other Entities' Relationships can be built up from them. - public typealias Pointers = ToManyRelationship + typealias Pointers = ToManyRelationship /// Get a pointer to this entity that can be used as a /// relationship to another entity. - public var pointer: Pointer { + var pointer: Pointer { return Pointer(entity: self) } - public func pointer(withMeta meta: MType, links: LType) -> ToOneRelationship { + func pointer(withMeta meta: MType, links: LType) -> ToOneRelationship { return ToOneRelationship(entity: self, meta: meta, links: links) } } @@ -419,19 +419,19 @@ public extension Entity where EntityRawIdType: JSONAPI.RawIdType { public extension Entity where EntityRawIdType == Unidentified { /// Create a new Entity from this one with a newly created /// unique Id of the given type. - public func identified(byType: RawIdType.Type) -> Entity { + func identified(byType: RawIdType.Type) -> Entity { return .init(attributes: attributes, relationships: relationships, meta: meta, links: links) } /// Create a new Entity from this one with the given Id. - public func identified(by id: RawIdType) -> Entity { + func identified(by id: RawIdType) -> Entity { return .init(id: Entity.Identifier(rawValue: id), attributes: attributes, relationships: relationships, meta: meta, links: links) } } public extension Entity where EntityRawIdType: CreatableRawIdType { /// Create a copy of this Entity with a new unique Id. - public func withNewIdentifier() -> Entity { + func withNewIdentifier() -> Entity { return Entity(attributes: attributes, relationships: relationships, meta: meta, links: links) } } @@ -485,14 +485,14 @@ public extension EntityProxy { /// Access to an Id of a `ToOneRelationship`. /// This allows you to write `entity ~> \.other` instead /// of `entity.relationships.other.id`. - public static func ~>(entity: Self, path: KeyPath>) -> OtherEntity.Identifier { + static func ~>(entity: Self, path: KeyPath>) -> OtherEntity.Identifier { return entity.relationships[keyPath: path].id } /// Access to an Id of an optional `ToOneRelationship`. /// This allows you to write `entity ~> \.other` instead /// of `entity.relationships.other?.id`. - public static func ~>(entity: Self, path: KeyPath?>) -> OtherEntity.Identifier { + static func ~>(entity: Self, path: KeyPath?>) -> OtherEntity.Identifier { // Implementation Note: This signature applies to `ToOneRelationship?` // whereas the one below applies to `ToOneRelationship?` return entity.relationships[keyPath: path]?.id @@ -501,7 +501,7 @@ public extension EntityProxy { /// Access to an Id of an optional `ToOneRelationship`. /// This allows you to write `entity ~> \.other` instead /// of `entity.relationships.other?.id`. - public static func ~>(entity: Self, path: KeyPath?>) -> OtherEntity.Identifier? { + static func ~>(entity: Self, path: KeyPath?>) -> OtherEntity.Identifier? { // Implementation Note: This signature applies to `ToOneRelationship?` // whereas the one above applies to `ToOneRelationship?` return entity.relationships[keyPath: path]?.id @@ -510,14 +510,14 @@ public extension EntityProxy { /// Access to all Ids of a `ToManyRelationship`. /// This allows you to write `entity ~> \.others` instead /// of `entity.relationships.others.ids`. - public static func ~>(entity: Self, path: KeyPath>) -> [OtherEntity.Identifier] { + static func ~>(entity: Self, path: KeyPath>) -> [OtherEntity.Identifier] { return entity.relationships[keyPath: path].ids } /// Access to all Ids of an optional `ToManyRelationship`. /// This allows you to write `entity ~> \.others` instead /// of `entity.relationships.others?.ids`. - public static func ~>(entity: Self, path: KeyPath?>) -> [OtherEntity.Identifier]? { + static func ~>(entity: Self, path: KeyPath?>) -> [OtherEntity.Identifier]? { return entity.relationships[keyPath: path]?.ids } } @@ -535,7 +535,7 @@ private enum ResourceObjectCodingKeys: String, CodingKey { } public extension Entity { - public func encode(to encoder: Encoder) throws { + func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: ResourceObjectCodingKeys.self) try container.encode(Entity.jsonType, forKey: .type) @@ -561,7 +561,7 @@ public extension Entity { } } - public init(from decoder: Decoder) throws { + init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: ResourceObjectCodingKeys.self) diff --git a/Sources/JSONAPITestLib/EntityCheck.swift b/Sources/JSONAPITestLib/EntityCheck.swift index 2a91e31..8c516f3 100644 --- a/Sources/JSONAPITestLib/EntityCheck.swift +++ b/Sources/JSONAPITestLib/EntityCheck.swift @@ -55,7 +55,7 @@ extension TransformedAttribute: _AttributeType {} extension Attribute: _AttributeType {} public extension Entity { - public static func check(_ entity: Entity) throws { + static func check(_ entity: Entity) throws { var problems = [EntityCheckError]() let attributesMirror = Mirror(reflecting: entity.attributes) From 16004051e98a9915e518368f8ec8415724557880 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sun, 17 Feb 2019 15:13:02 -0800 Subject: [PATCH 2/5] Update language version to 5.0 and specify deployment targets for iOS and Mac OS. --- Package.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 54df966..372087e 100644 --- a/Package.swift +++ b/Package.swift @@ -5,6 +5,10 @@ import PackageDescription let package = Package( name: "JSONAPI", + platforms: [ + .macOS(.v10_10), + .iOS(.v10) + ], products: [ .library( name: "JSONAPI", @@ -30,5 +34,5 @@ let package = Package( name: "JSONAPITestingTests", dependencies: ["JSONAPI", "JSONAPITesting"]) ], - swiftLanguageVersions: [.v4_2] + swiftLanguageVersions: [.v5] ) From b1adc6071922184bafaf1cf03332a189997ecd98 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Tue, 16 Apr 2019 21:52:50 -0700 Subject: [PATCH 3/5] Update package and podspec files --- JSONAPI.podspec | 6 +++--- Package.resolved | 4 ++-- Package.swift | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/JSONAPI.podspec b/JSONAPI.podspec index fe4dd9a..a87f919 100644 --- a/JSONAPI.podspec +++ b/JSONAPI.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "JSONAPI" - spec.version = "0.19.0" + spec.version = "0.20.0" spec.summary = "Swift Codable JSON API framework." # This description is used to generate tags and improve search results. @@ -132,10 +132,10 @@ See the JSON API Spec here: https://jsonapi.org/format/ # where they will only apply to your library. If you depend on other Podspecs # you can include multiple dependencies to ensure it works. - spec.swift_version = "4.2" + spec.swift_version = "5.0" # spec.requires_arc = true # spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } - spec.dependency "Poly", "~> 1.1" + spec.dependency "Poly", "~> 2.0" end diff --git a/Package.resolved b/Package.resolved index 920f7b5..fac7812 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/mattpolzin/Poly.git", "state": { "branch": null, - "revision": "77f45b8963a51c02d71fc4075eba5cff47ff0d07", - "version": "1.0.0" + "revision": "d24d4c1214dd05f89eb1182a46592856dd0a0645", + "version": "2.0.0" } } ] diff --git a/Package.swift b/Package.swift index 372087e..0789b25 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,7 @@ let package = Package( targets: ["JSONAPITesting"]) ], dependencies: [ - .package(url: "https://github.com/mattpolzin/Poly.git", from: "1.0.0"), + .package(url: "https://github.com/mattpolzin/Poly.git", from: "2.0.0"), ], targets: [ .target( From fb710c397b5458290ccff850a12fdf494cf30df1 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Tue, 16 Apr 2019 21:56:49 -0700 Subject: [PATCH 4/5] Entirely remove Result type that not only is unneeded with Swift 5 but also was not being used by this library (it was left over from before Poly became its own library). Fix a few redundent public warnings. --- Sources/JSONAPI/Result.swift | 45 -------------------- Tests/JSONAPITests/Poly/PolyProxyTests.swift | 6 +-- 2 files changed, 3 insertions(+), 48 deletions(-) delete mode 100644 Sources/JSONAPI/Result.swift diff --git a/Sources/JSONAPI/Result.swift b/Sources/JSONAPI/Result.swift deleted file mode 100644 index 326bdcc..0000000 --- a/Sources/JSONAPI/Result.swift +++ /dev/null @@ -1,45 +0,0 @@ -// -// Result.swift -// JSONAPI -// -// Created by Mathew Polzin on 12/5/18. -// - -enum Result { - case success(T) - case failure(E) - - var value: T? { - guard case .success(let val) = self else { - return nil - } - return val - } - - var error: E? { - guard case .failure(let err) = self else { - return nil - } - return err - } - - func map(_ transform: (T) -> U) -> Result { - switch self { - case .failure(let err): - return .failure(err) - case .success(let val): - return .success(transform(val)) - } - } -} - -extension Result: CustomStringConvertible where T: CustomStringConvertible, E: CustomStringConvertible { - var description: String { - switch self { - case .success(let val): - return String(describing: val) - case .failure(let err): - return String(describing: err) - } - } -} diff --git a/Tests/JSONAPITests/Poly/PolyProxyTests.swift b/Tests/JSONAPITests/Poly/PolyProxyTests.swift index 01dcfb6..a294f4e 100644 --- a/Tests/JSONAPITests/Poly/PolyProxyTests.swift +++ b/Tests/JSONAPITests/Poly/PolyProxyTests.swift @@ -86,10 +86,10 @@ public extension PolyProxyTests { public typealias Relationships = NoRelationships } - public typealias UserA = BasicEntity - public typealias UserB = BasicEntity + typealias UserA = BasicEntity + typealias UserB = BasicEntity - public typealias User = Poly2 + typealias User = Poly2 } extension Poly2: EntityProxy, JSONTyped where A == PolyProxyTests.UserA, B == PolyProxyTests.UserB { From db0f7329e42542b3754faa68c22440ac0f30bc64 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Tue, 16 Apr 2019 22:11:09 -0700 Subject: [PATCH 5/5] Comment out playground code that is failing in Xcode 10.2 --- .../Pages/Usage.xcplaygroundpage/Contents.swift | 4 ++++ JSONAPI.playground/contents.xcplayground | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/JSONAPI.playground/Pages/Usage.xcplaygroundpage/Contents.swift b/JSONAPI.playground/Pages/Usage.xcplaygroundpage/Contents.swift index 25b0235..cdd90fe 100644 --- a/JSONAPI.playground/Pages/Usage.xcplaygroundpage/Contents.swift +++ b/JSONAPI.playground/Pages/Usage.xcplaygroundpage/Contents.swift @@ -49,11 +49,15 @@ print("-----") // MARK: - Pass successfully parsed body to other parts of the code +/* + ---- CRASHING IN XCODE 10.2 PLAYGROUND ---- + if case let .data(bodyData) = peopleResponse.body { print("first person's name: \(bodyData.primary.values[0][\.fullName])") } else { print("no body data") } + */ // MARK: - Work in the abstract diff --git a/JSONAPI.playground/contents.xcplayground b/JSONAPI.playground/contents.xcplayground index e240eff..3da156e 100644 --- a/JSONAPI.playground/contents.xcplayground +++ b/JSONAPI.playground/contents.xcplayground @@ -1,5 +1,5 @@ - +