From dd9fefe080da74a8e1c0252f09dfcad62fdb43ed Mon Sep 17 00:00:00 2001 From: dadachi Date: Wed, 1 Apr 2026 12:55:27 +0900 Subject: [PATCH] Remove SwiftyJSON dependency, use JSONSerialization Replace SwiftyJSON with Foundation's JSONSerialization across the networking layer. JSONAPI classes now accept Any instead of JSON and use [String: Any] casting internally. Clean up redundant code in JSONAPIDocument and fix latent meta dictionary type bug. Co-Authored-By: Claude Opus 4.6 (1M context) --- CLAUDE.md | 1 - NativeAppTemplate.xcodeproj/project.pbxproj | 17 ---------- .../xcshareddata/swiftpm/Package.resolved | 11 +----- NativeAppTemplate/Login/SessionRequest.swift | 3 +- NativeAppTemplate/Login/SessionsService.swift | 6 ++-- NativeAppTemplate/Login/SignUpRequest.swift | 5 ++- NativeAppTemplate/Login/SignUpService.swift | 6 ++-- .../Networking/JSONAPI/JSONAPIDocument.swift | 34 +++++++------------ .../Networking/JSONAPI/JSONAPIError.swift | 21 ++++++------ .../JSONAPI/JSONAPIErrorSource.swift | 10 +++--- .../JSONAPI/JSONAPIRelationship.swift | 15 ++++---- .../Networking/JSONAPI/JSONAPIResource.swift | 31 +++++++++-------- .../Requests/AccountPasswordRequest.swift | 1 - .../Networking/Requests/ItemTagsRequest.swift | 13 ++++--- .../Networking/Requests/MeRequest.swift | 1 - .../Requests/PermissionsRequest.swift | 5 ++- .../Networking/Requests/Request.swift | 1 - .../Networking/Requests/ShopsRequest.swift | 9 +++-- .../Networking/Services/Service.swift | 6 ++-- .../Models/ShopkeeperTest.swift | 1 - .../Adapters/ItemTagAdapterTest.swift | 12 ++++--- .../Networking/Adapters/ShopAdapterTest.swift | 12 ++++--- .../Adapters/ShopkeeperAdapterTest.swift | 12 ++++--- .../ShopkeeperSignInAdapterTest.swift | 12 ++++--- 24 files changed, 103 insertions(+), 142 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index ecb39c1..d900a23 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -108,7 +108,6 @@ NativeAppTemplate/ ### Dependencies (Swift Package Manager) - KeychainAccess (4.2.2) - Secure credential storage -- SwiftyJSON (5.0.2) - JSON parsing - Swift Collections (1.1.4) - Additional data structures ### Testing diff --git a/NativeAppTemplate.xcodeproj/project.pbxproj b/NativeAppTemplate.xcodeproj/project.pbxproj index 292ff9b..e77cf83 100644 --- a/NativeAppTemplate.xcodeproj/project.pbxproj +++ b/NativeAppTemplate.xcodeproj/project.pbxproj @@ -40,7 +40,6 @@ 0150A36629B14BB300907F96 /* SendResetPassword.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0150A36529B14BB300907F96 /* SendResetPassword.swift */; }; 0158BA0125C174E0008EC9D5 /* ShopsRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0158BA0025C174E0008EC9D5 /* ShopsRequest.swift */; }; 015C78052B72DA2C00B6523C /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 015C78042B72DA2C00B6523C /* PrivacyInfo.xcprivacy */; }; - 0172030225A9634F008FD63B /* SwiftyJSON in Frameworks */ = {isa = PBXBuildFile; productRef = 0172030125A9634F008FD63B /* SwiftyJSON */; }; 0172033725A9642E008FD63B /* JSONAPIResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0172030825A9642D008FD63B /* JSONAPIResource.swift */; }; 0172033825A9642E008FD63B /* JSONAPIError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0172030925A9642E008FD63B /* JSONAPIError.swift */; }; 0172033925A9642E008FD63B /* JSONAPIRelationship.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0172030A25A9642E008FD63B /* JSONAPIRelationship.swift */; }; @@ -363,7 +362,6 @@ 012009FC299F1E190078A1F9 /* OrderedCollections in Frameworks */, 012009F8299F1E190078A1F9 /* Collections in Frameworks */, 012009FA299F1E190078A1F9 /* DequeModule in Frameworks */, - 0172030225A9634F008FD63B /* SwiftyJSON in Frameworks */, 0182D37025B258A7001E881D /* KeychainAccess in Frameworks */, ); }; @@ -856,7 +854,6 @@ ); name = NativeAppTemplate; packageProductDependencies = ( - 0172030125A9634F008FD63B /* SwiftyJSON */, 0182D36F25B258A7001E881D /* KeychainAccess */, 012009F7299F1E190078A1F9 /* Collections */, 012009F9299F1E190078A1F9 /* DequeModule */, @@ -916,7 +913,6 @@ ); mainGroup = 011F6DE4259EF16400BED22E; packageReferences = ( - 0172030025A9634F008FD63B /* XCRemoteSwiftPackageReference "SwiftyJSON" */, 0182D36E25B258A7001E881D /* XCRemoteSwiftPackageReference "KeychainAccess" */, 012009F6299F1E190078A1F9 /* XCRemoteSwiftPackageReference "swift-collections" */, ); @@ -1529,14 +1525,6 @@ minimumVersion = 1.0.5; }; }; - 0172030025A9634F008FD63B /* XCRemoteSwiftPackageReference "SwiftyJSON" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/SwiftyJSON/SwiftyJSON"; - requirement = { - kind = upToNextMajorVersion; - minimumVersion = 5.0.1; - }; - }; 0182D36E25B258A7001E881D /* XCRemoteSwiftPackageReference "KeychainAccess" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/kishikawakatsumi/KeychainAccess.git"; @@ -1563,11 +1551,6 @@ package = 012009F6299F1E190078A1F9 /* XCRemoteSwiftPackageReference "swift-collections" */; productName = OrderedCollections; }; - 0172030125A9634F008FD63B /* SwiftyJSON */ = { - isa = XCSwiftPackageProductDependency; - package = 0172030025A9634F008FD63B /* XCRemoteSwiftPackageReference "SwiftyJSON" */; - productName = SwiftyJSON; - }; 0182D36F25B258A7001E881D /* KeychainAccess */ = { isa = XCSwiftPackageProductDependency; package = 0182D36E25B258A7001E881D /* XCRemoteSwiftPackageReference "KeychainAccess" */; diff --git a/NativeAppTemplate.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/NativeAppTemplate.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 22fb1b0..218e016 100644 --- a/NativeAppTemplate.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/NativeAppTemplate.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "6b1231380720b7bc51910b56c46999018c0dc9e0af9279ee365eff309cd750a5", + "originHash" : "4a4ea0d8d95fb5961671898aaad375a7121daa5f945a12981cacc842da109bd7", "pins" : [ { "identity" : "keychainaccess", @@ -18,15 +18,6 @@ "revision" : "671108c96644956dddcd89dd59c203dcdb36cec7", "version" : "1.1.4" } - }, - { - "identity" : "swiftyjson", - "kind" : "remoteSourceControl", - "location" : "https://github.com/SwiftyJSON/SwiftyJSON", - "state" : { - "revision" : "af76cf3ef710b6ca5f8c05f3a31307d44a3c5828", - "version" : "5.0.2" - } } ], "version" : 3 diff --git a/NativeAppTemplate/Login/SessionRequest.swift b/NativeAppTemplate/Login/SessionRequest.swift index 69204c8..c10ba31 100644 --- a/NativeAppTemplate/Login/SessionRequest.swift +++ b/NativeAppTemplate/Login/SessionRequest.swift @@ -4,7 +4,6 @@ // import Foundation -import SwiftyJSON struct MakeSessionRequest: Request { typealias Response = Shopkeeper @@ -31,7 +30,7 @@ struct MakeSessionRequest: Request { let password: String func handle(response: Data) throws -> Shopkeeper { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) let shopkeepers = try doc.data.map { try ShopkeeperSignInAdapter.process(resource: $0) } return shopkeepers.first! diff --git a/NativeAppTemplate/Login/SessionsService.swift b/NativeAppTemplate/Login/SessionsService.swift index 92c654f..836f81f 100644 --- a/NativeAppTemplate/Login/SessionsService.swift +++ b/NativeAppTemplate/Login/SessionsService.swift @@ -4,7 +4,6 @@ // import Foundation -import SwiftyJSON struct SessionsService { var networkClient: NativeAppTemplateAPI @@ -76,11 +75,10 @@ extension SessionsService { guard statusCode.map((200 ..< 300).contains) == true else { var errorMessage: String? - var json: JSON? do { - json = try JSON(data: data) - if let json, let theErrorMessage = json["error_message"].string { + if let json = try JSONSerialization.jsonObject(with: data) as? [String: Any], + let theErrorMessage = json["error_message"] as? String { errorMessage = theErrorMessage } } catch { diff --git a/NativeAppTemplate/Login/SignUpRequest.swift b/NativeAppTemplate/Login/SignUpRequest.swift index f0b764a..faea4d7 100644 --- a/NativeAppTemplate/Login/SignUpRequest.swift +++ b/NativeAppTemplate/Login/SignUpRequest.swift @@ -4,7 +4,6 @@ // import Foundation -import SwiftyJSON struct MakeShopkeeperRequest: Request { typealias Response = Shopkeeper @@ -30,7 +29,7 @@ struct MakeShopkeeperRequest: Request { let signUp: SignUp func handle(response: Data) throws -> Shopkeeper { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) let shopkeepers = try doc.data.map { try ShopkeeperSignInAdapter.process(resource: $0) } return shopkeepers.first! @@ -64,7 +63,7 @@ struct UpdateShopkeeperRequest: Request { // MARK: - Internal func handle(response: Data) throws -> Response { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) let shopkeepers = try doc.data.map { try ShopkeeperSignInAdapter.process(resource: $0) } guard let shopkeeper = shopkeepers.first, diff --git a/NativeAppTemplate/Login/SignUpService.swift b/NativeAppTemplate/Login/SignUpService.swift index 90af43c..7d76046 100644 --- a/NativeAppTemplate/Login/SignUpService.swift +++ b/NativeAppTemplate/Login/SignUpService.swift @@ -4,7 +4,6 @@ // import Foundation -import SwiftyJSON struct SignUpsService { var networkClient = NativeAppTemplateAPI() @@ -90,11 +89,10 @@ extension SignUpsService { guard statusCode.map((200 ..< 300).contains) == true else { var errorMessage: String? - var json: JSON? do { - json = try JSON(data: data) - if let json, let theErrorMessage = json["error_message"].string { + if let json = try JSONSerialization.jsonObject(with: data) as? [String: Any], + let theErrorMessage = json["error_message"] as? String { errorMessage = theErrorMessage } } catch { diff --git a/NativeAppTemplate/Networking/JSONAPI/JSONAPIDocument.swift b/NativeAppTemplate/Networking/JSONAPI/JSONAPIDocument.swift index 9816d84..7f82017 100644 --- a/NativeAppTemplate/Networking/JSONAPI/JSONAPIDocument.swift +++ b/NativeAppTemplate/Networking/JSONAPI/JSONAPIDocument.swift @@ -4,7 +4,6 @@ // import struct Foundation.URL -import SwiftyJSON class JSONAPIDocument { // MARK: - Properties @@ -17,36 +16,27 @@ class JSONAPIDocument { // MARK: - Initializers - convenience init(_ json: JSON) { + convenience init(_ json: Any) { self.init() - data = json["data"].arrayValue.map { JSONAPIResource($0, parent: self) } - meta = json["meta"].dictionaryObject ?? [:] - included = json["included"].arrayValue.map { JSONAPIResource($0, parent: self) } - errors = json["error"].arrayValue.map { JSONAPIError($0) } + guard let dict = json as? [String: Any] else { return } - if let dataArray = json["data"].array { + meta = dict["meta"] as? [String: Any] ?? [:] + errors = (dict["error"] as? [[String: Any]] ?? []).map { JSONAPIError($0) } + + if let dataArray = dict["data"] as? [[String: Any]] { data = dataArray.map { JSONAPIResource($0, parent: self) } - } else { - data = [JSONAPIResource(json["data"], parent: self)] + } else if let dataDict = dict["data"] as? [String: Any] { + data = [JSONAPIResource(dataDict, parent: self)] } - if let includedArray = json["included"].array { + if let includedArray = dict["included"] as? [[String: Any]] { included = includedArray.map { JSONAPIResource($0, parent: self) } - } else { - included = [JSONAPIResource(json["included"], parent: self)] - } - - if let linksDict = json["links"].dictionaryObject { - for link in linksDict { - if let strValue = link.value as? String, - let url = URL(string: strValue) { - links[link.key] = url - } - } + } else if let includedDict = dict["included"] as? [String: Any] { + included = [JSONAPIResource(includedDict, parent: self)] } - if let linksDict = json["links"].dictionaryObject { + if let linksDict = dict["links"] as? [String: Any] { for link in linksDict { if let strValue = link.value as? String, let url = URL(string: strValue) { diff --git a/NativeAppTemplate/Networking/JSONAPI/JSONAPIError.swift b/NativeAppTemplate/Networking/JSONAPI/JSONAPIError.swift index 58ecfb0..13f01a0 100644 --- a/NativeAppTemplate/Networking/JSONAPI/JSONAPIError.swift +++ b/NativeAppTemplate/Networking/JSONAPI/JSONAPIError.swift @@ -4,7 +4,6 @@ // import struct Foundation.URL -import SwiftyJSON public class JSONAPIError { // MARK: - Properties @@ -20,12 +19,14 @@ public class JSONAPIError { // MARK: - Initializers - convenience init(_ json: JSON) { + convenience init(_ json: Any) { self.init() - id = json["id"].stringValue + guard let dict = json as? [String: Any] else { return } - if let linksDict = json["links"].dictionaryObject { + id = (dict["id"] as? String) ?? "" + + if let linksDict = dict["links"] as? [String: Any] { for link in linksDict { if let strValue = link.value as? String, let url = URL(string: strValue) { @@ -34,11 +35,11 @@ public class JSONAPIError { } } - status = json["status"].stringValue - code = json["code"].stringValue - title = json["title"].stringValue - detail = json["detail"].stringValue - source = JSONAPIErrorSource(json["source"]) - meta = json["meta"].dictionaryValue + status = (dict["status"] as? String) ?? "" + code = (dict["code"] as? String) ?? "" + title = (dict["title"] as? String) ?? "" + detail = (dict["detail"] as? String) ?? "" + source = JSONAPIErrorSource(dict["source"] as Any) + meta = dict["meta"] as? [String: Any] ?? [:] } } diff --git a/NativeAppTemplate/Networking/JSONAPI/JSONAPIErrorSource.swift b/NativeAppTemplate/Networking/JSONAPI/JSONAPIErrorSource.swift index 01fbe2d..f46802b 100644 --- a/NativeAppTemplate/Networking/JSONAPI/JSONAPIErrorSource.swift +++ b/NativeAppTemplate/Networking/JSONAPI/JSONAPIErrorSource.swift @@ -3,8 +3,6 @@ // NativeAppTemplate // -import SwiftyJSON - public class JSONAPIErrorSource { // MARK: - Properties @@ -13,10 +11,12 @@ public class JSONAPIErrorSource { // MARK: - Initializers - convenience init(_ json: JSON) { + convenience init(_ json: Any) { self.init() - pointer = json["pointer"].stringValue - parameter = json["parameter"].stringValue + guard let dict = json as? [String: Any] else { return } + + pointer = (dict["pointer"] as? String) ?? "" + parameter = (dict["parameter"] as? String) ?? "" } } diff --git a/NativeAppTemplate/Networking/JSONAPI/JSONAPIRelationship.swift b/NativeAppTemplate/Networking/JSONAPI/JSONAPIRelationship.swift index b1f6351..6d67f3b 100644 --- a/NativeAppTemplate/Networking/JSONAPI/JSONAPIRelationship.swift +++ b/NativeAppTemplate/Networking/JSONAPI/JSONAPIRelationship.swift @@ -4,7 +4,6 @@ // import struct Foundation.URL -import SwiftyJSON public class JSONAPIRelationship { // MARK: - Properties @@ -17,20 +16,22 @@ public class JSONAPIRelationship { // MARK: - Initializers convenience init( - _ json: JSON, + _ json: Any, type: String, parent: JSONAPIDocument? ) { self.init() + guard let dict = json as? [String: Any] else { return } + self.type = type - meta = json["meta"].dictionaryObject ?? [:] - data = json["data"].arrayValue.map { + meta = dict["meta"] as? [String: Any] ?? [:] + data = (dict["data"] as? [[String: Any]] ?? []).map { JSONAPIResource($0, parent: nil) } - let nonArrayJSON = json["data"] - let nonArrayJSONAPIResource = JSONAPIResource(nonArrayJSON, parent: nil) - data.append(nonArrayJSONAPIResource) + if let singleData = dict["data"] as? [String: Any] { + data.append(JSONAPIResource(singleData, parent: nil)) + } } } diff --git a/NativeAppTemplate/Networking/JSONAPI/JSONAPIResource.swift b/NativeAppTemplate/Networking/JSONAPI/JSONAPIResource.swift index 05b8fe1..a7bb3b5 100644 --- a/NativeAppTemplate/Networking/JSONAPI/JSONAPIResource.swift +++ b/NativeAppTemplate/Networking/JSONAPI/JSONAPIResource.swift @@ -4,7 +4,6 @@ // import struct Foundation.URL -import SwiftyJSON public class JSONAPIResource { // MARK: - Properties @@ -33,31 +32,35 @@ public class JSONAPIResource { // MARK: - Initializers convenience init( - _ json: JSON, + _ json: Any, parent: JSONAPIDocument? ) { self.init() + guard let dict = json as? [String: Any] else { return } + if let doc = parent { self.parent = doc } - id = json["id"].stringValue - type = json["type"].stringValue + id = (dict["id"] as? String) ?? "" + type = (dict["type"] as? String) ?? "" - for relationship in json["relationships"].dictionaryValue { - relationships.append( - JSONAPIRelationship( - relationship.value, - type: relationship.key, - parent: nil + if let rels = dict["relationships"] as? [String: Any] { + for (key, value) in rels { + relationships.append( + JSONAPIRelationship( + value, + type: key, + parent: nil + ) ) - ) + } } - attributes = json["attributes"].dictionaryObject ?? [:] + attributes = dict["attributes"] as? [String: Any] ?? [:] - if let linksDict = json["links"].dictionaryObject { + if let linksDict = dict["links"] as? [String: Any] { for link in linksDict { if let strValue = link.value as? String, let url = URL(string: strValue) { @@ -66,7 +69,7 @@ public class JSONAPIResource { } } - meta = json["meta"].dictionaryValue + meta = dict["meta"] as? [String: Any] ?? [:] } } diff --git a/NativeAppTemplate/Networking/Requests/AccountPasswordRequest.swift b/NativeAppTemplate/Networking/Requests/AccountPasswordRequest.swift index 698a83c..4b77317 100644 --- a/NativeAppTemplate/Networking/Requests/AccountPasswordRequest.swift +++ b/NativeAppTemplate/Networking/Requests/AccountPasswordRequest.swift @@ -4,7 +4,6 @@ // import Foundation -import SwiftyJSON struct UpdateAccountPasswordRequest: Request { typealias Response = Void diff --git a/NativeAppTemplate/Networking/Requests/ItemTagsRequest.swift b/NativeAppTemplate/Networking/Requests/ItemTagsRequest.swift index 38f715d..b0c3e72 100644 --- a/NativeAppTemplate/Networking/Requests/ItemTagsRequest.swift +++ b/NativeAppTemplate/Networking/Requests/ItemTagsRequest.swift @@ -4,7 +4,6 @@ // import Foundation -import SwiftyJSON struct GetItemTagsRequest: Request { typealias Response = [ItemTag] @@ -29,7 +28,7 @@ struct GetItemTagsRequest: Request { // MARK: - Internal func handle(response: Data) throws -> Response { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) return try doc.data.map { try ItemTagAdapter.process(resource: $0) } } @@ -60,7 +59,7 @@ struct GetItemTagDetailRequest: Request { // MARK: - Internal func handle(response: Data) throws -> Response { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) let itemTags = try doc.data.map { try ItemTagAdapter.process(resource: $0) } @@ -101,7 +100,7 @@ struct MakeItemTagRequest: Request { // MARK: - Internal func handle(response: Data) throws -> ItemTag { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) let itemTags = try doc.data.map { try ItemTagAdapter.process(resource: $0) } guard let itemTag = itemTags.first, @@ -141,7 +140,7 @@ struct UpdateItemTagRequest: Request { // MARK: - Internal func handle(response: Data) throws -> Response { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) let itemTags = try doc.data.map { try ItemTagAdapter.process(resource: $0) } guard let theItemTag = itemTags.first, @@ -205,7 +204,7 @@ struct CompleteItemTagRequest: Request { // MARK: - Internal func handle(response: Data) throws -> Response { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) let itemTags = try doc.data.map { try ItemTagAdapter.process(resource: $0) } guard let itemTag = itemTags.first, @@ -242,7 +241,7 @@ struct ResetItemTagRequest: Request { // MARK: - Internal func handle(response: Data) throws -> Response { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) let itemTags = try doc.data.map { try ItemTagAdapter.process(resource: $0) } guard let theItemTag = itemTags.first, diff --git a/NativeAppTemplate/Networking/Requests/MeRequest.swift b/NativeAppTemplate/Networking/Requests/MeRequest.swift index 2749491..dc258af 100644 --- a/NativeAppTemplate/Networking/Requests/MeRequest.swift +++ b/NativeAppTemplate/Networking/Requests/MeRequest.swift @@ -4,7 +4,6 @@ // import Foundation -import SwiftyJSON struct UpdateConfirmedPrivacyVersionRequest: Request { typealias Response = Void diff --git a/NativeAppTemplate/Networking/Requests/PermissionsRequest.swift b/NativeAppTemplate/Networking/Requests/PermissionsRequest.swift index ab88d66..e4dded1 100644 --- a/NativeAppTemplate/Networking/Requests/PermissionsRequest.swift +++ b/NativeAppTemplate/Networking/Requests/PermissionsRequest.swift @@ -3,8 +3,7 @@ // NativeAppTemplate // -import struct Foundation.Data -import SwiftyJSON +import Foundation struct PermissionsResponse: Sendable { var iosAppVersion: Int @@ -35,7 +34,7 @@ struct PermissionsRequest: Request { // MARK: - Internal func handle(response: Data) throws -> Response { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) guard let iosAppVersion = doc.meta["ios_app_version"] as? Int else { diff --git a/NativeAppTemplate/Networking/Requests/Request.swift b/NativeAppTemplate/Networking/Requests/Request.swift index d8ad2ae..31173a4 100644 --- a/NativeAppTemplate/Networking/Requests/Request.swift +++ b/NativeAppTemplate/Networking/Requests/Request.swift @@ -4,7 +4,6 @@ // import struct Foundation.Data -import SwiftyJSON enum HTTPMethod: String { case GET diff --git a/NativeAppTemplate/Networking/Requests/ShopsRequest.swift b/NativeAppTemplate/Networking/Requests/ShopsRequest.swift index bdf1233..bca2f14 100644 --- a/NativeAppTemplate/Networking/Requests/ShopsRequest.swift +++ b/NativeAppTemplate/Networking/Requests/ShopsRequest.swift @@ -4,7 +4,6 @@ // import Foundation -import SwiftyJSON struct GetShopsRequest: Request { typealias Response = (shops: [Shop], limitCount: Int, createdShopsCount: Int) @@ -27,7 +26,7 @@ struct GetShopsRequest: Request { // MARK: - Internal func handle(response: Data) throws -> Response { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) let shops = try doc.data.map { try ShopAdapter.process(resource: $0) } guard let limitCount = doc.meta["limit_count"] as? Int else { @@ -68,7 +67,7 @@ struct GetShopDetailRequest: Request { // MARK: - Internal func handle(response: Data) throws -> Response { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) let shops = try doc.data.map { try ShopAdapter.process(resource: $0) } @@ -107,7 +106,7 @@ struct MakeShopRequest: Request { // MARK: - Internal func handle(response: Data) throws -> Shop { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) let shops = try doc.data.map { try ShopAdapter.process(resource: $0) } guard let shop = shops.first, @@ -146,7 +145,7 @@ struct UpdateShopRequest: Request { // MARK: - Internal func handle(response: Data) throws -> Response { - let json = try JSON(data: response) + let json = try JSONSerialization.jsonObject(with: response) let doc = JSONAPIDocument(json) let shops = try doc.data.map { try ShopAdapter.process(resource: $0) } guard let shop = shops.first, diff --git a/NativeAppTemplate/Networking/Services/Service.swift b/NativeAppTemplate/Networking/Services/Service.swift index 8445e4f..7ce04db 100644 --- a/NativeAppTemplate/Networking/Services/Service.swift +++ b/NativeAppTemplate/Networking/Services/Service.swift @@ -4,7 +4,6 @@ // import Foundation -import SwiftyJSON protocol Service { var networkClient: NativeAppTemplateAPI { get } @@ -74,11 +73,10 @@ extension Service { guard statusCode.map((200 ..< 300).contains) == true else { var errorMessage: String? - var json: JSON? do { - json = try JSON(data: data) - if let json, let theErrorMessage = json["error_message"].string { + if let json = try JSONSerialization.jsonObject(with: data) as? [String: Any], + let theErrorMessage = json["error_message"] as? String { errorMessage = theErrorMessage } } catch { diff --git a/NativeAppTemplateTests/Models/ShopkeeperTest.swift b/NativeAppTemplateTests/Models/ShopkeeperTest.swift index 193d862..0cca9cf 100644 --- a/NativeAppTemplateTests/Models/ShopkeeperTest.swift +++ b/NativeAppTemplateTests/Models/ShopkeeperTest.swift @@ -4,7 +4,6 @@ // @testable import NativeAppTemplate -import SwiftyJSON import Testing struct ShopkeeperTest { diff --git a/NativeAppTemplateTests/Networking/Adapters/ItemTagAdapterTest.swift b/NativeAppTemplateTests/Networking/Adapters/ItemTagAdapterTest.swift index 3e00cc7..3ff07c5 100644 --- a/NativeAppTemplateTests/Networking/Adapters/ItemTagAdapterTest.swift +++ b/NativeAppTemplateTests/Networking/Adapters/ItemTagAdapterTest.swift @@ -4,11 +4,10 @@ // @testable import NativeAppTemplate -import SwiftyJSON import Testing struct ItemTagAdapterTest { - let sampleResource: JSON = [ + let sampleResource: [String: Any] = [ "id": "5712F2DF-DFC7-A3AA-66BC-191203654A1A", "type": "item_tag", "attributes": [ @@ -24,8 +23,8 @@ struct ItemTagAdapterTest { ] ] - func makeJsonAPIResource(for dict: JSON) throws -> JSONAPIResource { - let json: JSON = [ + func makeJsonAPIResource(for dict: [String: Any]) throws -> JSONAPIResource { + let json: [String: Any] = [ "data": [ dict ] @@ -55,7 +54,10 @@ struct ItemTagAdapterTest { @Test func missingnAccountIdThrows() throws { var sample = sampleResource - sample["attributes"].dictionaryObject?.removeValue(forKey: "shop_id") + if var attributes = sample["attributes"] as? [String: Any] { + attributes.removeValue(forKey: "shop_id") + sample["attributes"] = attributes + } let resource = try makeJsonAPIResource(for: sample) diff --git a/NativeAppTemplateTests/Networking/Adapters/ShopAdapterTest.swift b/NativeAppTemplateTests/Networking/Adapters/ShopAdapterTest.swift index 3fde56a..23cf258 100644 --- a/NativeAppTemplateTests/Networking/Adapters/ShopAdapterTest.swift +++ b/NativeAppTemplateTests/Networking/Adapters/ShopAdapterTest.swift @@ -4,11 +4,10 @@ // @testable import NativeAppTemplate -import SwiftyJSON import Testing struct ShopAdapterTest { - let sampleResource: JSON = [ + let sampleResource: [String: Any] = [ "id": "5712F2DF-DFC7-A3AA-66BC-191203654A1C", "type": "shop", "attributes": [ @@ -44,8 +43,8 @@ struct ShopAdapterTest { ] ] - func makeJsonAPIResource(for dict: JSON) throws -> JSONAPIResource { - let json: JSON = [ + func makeJsonAPIResource(for dict: [String: Any]) throws -> JSONAPIResource { + let json: [String: Any] = [ "data": [ dict ] @@ -75,7 +74,10 @@ struct ShopAdapterTest { @Test func missingnNameThrows() throws { var sample = sampleResource - sample["attributes"].dictionaryObject?.removeValue(forKey: "name") + if var attributes = sample["attributes"] as? [String: Any] { + attributes.removeValue(forKey: "name") + sample["attributes"] = attributes + } let resource = try makeJsonAPIResource(for: sample) diff --git a/NativeAppTemplateTests/Networking/Adapters/ShopkeeperAdapterTest.swift b/NativeAppTemplateTests/Networking/Adapters/ShopkeeperAdapterTest.swift index 38e5a95..7cedd36 100644 --- a/NativeAppTemplateTests/Networking/Adapters/ShopkeeperAdapterTest.swift +++ b/NativeAppTemplateTests/Networking/Adapters/ShopkeeperAdapterTest.swift @@ -4,11 +4,10 @@ // @testable import NativeAppTemplate -import SwiftyJSON import Testing struct ShopkeeperAdapterTest { - let sampleResource: JSON = [ + let sampleResource: [String: Any] = [ "id": "5712F2DF-DFC7-A3AA-66BC-191203654A1C", "type": "shopkeeper", "attributes": [ @@ -18,8 +17,8 @@ struct ShopkeeperAdapterTest { ] ] - func makeJsonAPIResource(for dict: JSON) throws -> JSONAPIResource { - let json: JSON = [ + func makeJsonAPIResource(for dict: [String: Any]) throws -> JSONAPIResource { + let json: [String: Any] = [ "data": [ dict ] @@ -49,7 +48,10 @@ struct ShopkeeperAdapterTest { @Test func missingnNameThrows() throws { var sample = sampleResource - sample["attributes"].dictionaryObject?.removeValue(forKey: "name") + if var attributes = sample["attributes"] as? [String: Any] { + attributes.removeValue(forKey: "name") + sample["attributes"] = attributes + } let resource = try makeJsonAPIResource(for: sample) diff --git a/NativeAppTemplateTests/Networking/Adapters/ShopkeeperSignInAdapterTest.swift b/NativeAppTemplateTests/Networking/Adapters/ShopkeeperSignInAdapterTest.swift index e26136b..d164329 100644 --- a/NativeAppTemplateTests/Networking/Adapters/ShopkeeperSignInAdapterTest.swift +++ b/NativeAppTemplateTests/Networking/Adapters/ShopkeeperSignInAdapterTest.swift @@ -4,11 +4,10 @@ // @testable import NativeAppTemplate -import SwiftyJSON import Testing struct ShopkeeperSignInAdapterTest { - let sampleResource: JSON = [ + let sampleResource: [String: Any] = [ "id": "5712F2DF-DFC7-A3AA-66BC-191203654A1C", "type": "shopkeeper_sign_in", "attributes": [ @@ -23,8 +22,8 @@ struct ShopkeeperSignInAdapterTest { ] ] - func makeJsonAPIResource(for dict: JSON) throws -> JSONAPIResource { - let json: JSON = [ + func makeJsonAPIResource(for dict: [String: Any]) throws -> JSONAPIResource { + let json: [String: Any] = [ "data": [ dict ] @@ -54,7 +53,10 @@ struct ShopkeeperSignInAdapterTest { @Test func missingnNameThrows() throws { var sample = sampleResource - sample["attributes"].dictionaryObject?.removeValue(forKey: "name") + if var attributes = sample["attributes"] as? [String: Any] { + attributes.removeValue(forKey: "name") + sample["attributes"] = attributes + } let resource = try makeJsonAPIResource(for: sample)