Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 0 additions & 17 deletions NativeAppTemplate.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -363,7 +362,6 @@
012009FC299F1E190078A1F9 /* OrderedCollections in Frameworks */,
012009F8299F1E190078A1F9 /* Collections in Frameworks */,
012009FA299F1E190078A1F9 /* DequeModule in Frameworks */,
0172030225A9634F008FD63B /* SwiftyJSON in Frameworks */,
0182D37025B258A7001E881D /* KeychainAccess in Frameworks */,
);
};
Expand Down Expand Up @@ -856,7 +854,6 @@
);
name = NativeAppTemplate;
packageProductDependencies = (
0172030125A9634F008FD63B /* SwiftyJSON */,
0182D36F25B258A7001E881D /* KeychainAccess */,
012009F7299F1E190078A1F9 /* Collections */,
012009F9299F1E190078A1F9 /* DequeModule */,
Expand Down Expand Up @@ -916,7 +913,6 @@
);
mainGroup = 011F6DE4259EF16400BED22E;
packageReferences = (
0172030025A9634F008FD63B /* XCRemoteSwiftPackageReference "SwiftyJSON" */,
0182D36E25B258A7001E881D /* XCRemoteSwiftPackageReference "KeychainAccess" */,
012009F6299F1E190078A1F9 /* XCRemoteSwiftPackageReference "swift-collections" */,
);
Expand Down Expand Up @@ -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";
Expand All @@ -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" */;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions NativeAppTemplate/Login/SessionRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import Foundation
import SwiftyJSON

struct MakeSessionRequest: Request {
typealias Response = Shopkeeper
Expand All @@ -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!
Expand Down
6 changes: 2 additions & 4 deletions NativeAppTemplate/Login/SessionsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import Foundation
import SwiftyJSON

struct SessionsService {
var networkClient: NativeAppTemplateAPI
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions NativeAppTemplate/Login/SignUpRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import Foundation
import SwiftyJSON

struct MakeShopkeeperRequest: Request {
typealias Response = Shopkeeper
Expand All @@ -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!
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions NativeAppTemplate/Login/SignUpService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import Foundation
import SwiftyJSON

struct SignUpsService {
var networkClient = NativeAppTemplateAPI()
Expand Down Expand Up @@ -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 {
Expand Down
34 changes: 12 additions & 22 deletions NativeAppTemplate/Networking/JSONAPI/JSONAPIDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import struct Foundation.URL
import SwiftyJSON

class JSONAPIDocument {
// MARK: - Properties
Expand All @@ -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) {
Expand Down
21 changes: 11 additions & 10 deletions NativeAppTemplate/Networking/JSONAPI/JSONAPIError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import struct Foundation.URL
import SwiftyJSON

public class JSONAPIError {
// MARK: - Properties
Expand All @@ -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) {
Expand All @@ -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] ?? [:]
}
}
10 changes: 5 additions & 5 deletions NativeAppTemplate/Networking/JSONAPI/JSONAPIErrorSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// NativeAppTemplate
//

import SwiftyJSON

public class JSONAPIErrorSource {
// MARK: - Properties

Expand All @@ -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) ?? ""
}
}
15 changes: 8 additions & 7 deletions NativeAppTemplate/Networking/JSONAPI/JSONAPIRelationship.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import struct Foundation.URL
import SwiftyJSON

public class JSONAPIRelationship {
// MARK: - Properties
Expand All @@ -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))
}
}
}
Loading
Loading