Skip to content

Commit db33f6a

Browse files
refactor: seperate network module
1 parent 08525a5 commit db33f6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1593
-340
lines changed

.mise.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[tools]
2-
tuist = "4.26.0"
2+
tuist = "4.34.3"

Package.resolved

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"kind" : "remoteSourceControl",
66
"location" : "https://github.com/Alamofire/Alamofire",
77
"state" : {
8-
"revision" : "f455c2975872ccd2d9c81594c658af65716e9b9a",
9-
"version" : "5.9.1"
8+
"revision" : "e16d3481f5ed35f0472cb93350085853d754913f",
9+
"version" : "5.10.1"
1010
}
1111
},
1212
{
@@ -50,8 +50,8 @@
5050
"kind" : "remoteSourceControl",
5151
"location" : "https://github.com/gonzalezreal/NetworkImage",
5252
"state" : {
53-
"revision" : "7aff8d1b31148d32c5933d75557d42f6323ee3d1",
54-
"version" : "6.0.0"
53+
"revision" : "2849f5323265386e200484b0d0f896e73c3411b9",
54+
"version" : "6.0.1"
5555
}
5656
},
5757
{
@@ -68,26 +68,26 @@
6868
"kind" : "remoteSourceControl",
6969
"location" : "https://github.com/realm/realm-core.git",
7070
"state" : {
71-
"revision" : "c2552e1d36867cb42b28130e894a81fc17081062",
72-
"version" : "14.12.0"
71+
"revision" : "85eeca41654cc9070ad81a21a4b1d153ad467c33",
72+
"version" : "14.13.1"
7373
}
7474
},
7575
{
7676
"identity" : "realm-swift",
7777
"kind" : "remoteSourceControl",
7878
"location" : "https://github.com/realm/realm-swift",
7979
"state" : {
80-
"revision" : "5221a83dc720823e3017493394d00d49ccf13446",
81-
"version" : "10.52.3"
80+
"revision" : "5553cfd1c789efdb3d6daf7f0cc0733cfe601846",
81+
"version" : "10.54.1"
8282
}
8383
},
8484
{
8585
"identity" : "rxswift",
8686
"kind" : "remoteSourceControl",
8787
"location" : "https://github.com/ReactiveX/RxSwift.git",
8888
"state" : {
89-
"revision" : "b06a8c8596e4c3e8e7788e08e720e3248563ce6a",
90-
"version" : "6.7.1"
89+
"revision" : "c7c7d2cf50a3211fe2843f76869c698e4e417930",
90+
"version" : "6.8.0"
9191
}
9292
},
9393
{

Project.swift

+15-6
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,38 @@ let project = Project.app(
7878
Module(
7979
name: "Core",
8080
hasResources: true,
81-
hasUnitTest: true
81+
hasUnitTest: true,
82+
dependencies: ["SuperLog", "NetworkKit"]
8283
),
8384
Module(
8485
name: "CommonUI",
8586
hasResources: true,
8687
hasUITest: true,
87-
dependencies: ["Core"]
88+
dependencies: ["Core", "SuperLog"]
89+
),
90+
Module(
91+
name: "NetworkKit",
92+
hasUnitTest: true,
93+
dependencies: ["SuperLog"]
94+
),
95+
Module(
96+
name: "SuperLog"
8897
),
8998
Module(
9099
name: "Home",
91100
hasUnitTest: true,
92101
hasUITest: true,
93-
dependencies: ["Core", "CommonUI", "Todo", "News"]
102+
dependencies: ["Core", "CommonUI", "SuperLog", "Todo", "News"]
94103
),
95104
Module(
96105
name: "Todo",
97-
dependencies: ["Core", "CommonUI"]
106+
dependencies: ["Core", "CommonUI", "SuperLog"]
98107
),
99108
Module(
100109
name: "News",
101110
hasResources: true,
102111
hasUITest: true,
103-
dependencies: ["Core", "CommonUI"]
112+
dependencies: ["Core", "CommonUI", "SuperLog", "NetworkKit"]
104113
)
105114
],
106115
externalDependencies: [
@@ -115,7 +124,7 @@ let project = Project.app(
115124
// We need both "RealmSwift" and "Realm" to solve the "Undefined symbol" issue.
116125
.external(name: "RealmSwift"),
117126
.external(name: "Realm"),
118-
.external(name: "MarkdownUI"),
127+
.external(name: "MarkdownUI")
119128
],
120129
coreDataModels: []
121130
)

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,18 @@ A collection of animation related SwiftUI features.
103103

104104
<img src="images/animation.gif" width=250/>
105105

106+
### UI Testing with Mock data
107+
108+
Checkout the "News" module to get an example for how to run an UI test using mock data.
109+
106110
## Playground Books
107111

108112
Check `Playgrounds` directory for the books.
109113

110114
### **GCD and Structured Concurrency Model:** A quick guide about the GCD (`DispatchQueue` etc.) and Structured Concurrency Model (`Task`, `actor`, `Sendable` etc.)
111115

116+
### **Combine:** An introduction guide for the Combine framework.
117+
112118
<img src="images/GCD and Structured Concurrency Model.png" width=300/>
113119

114120
## Others
@@ -299,6 +305,7 @@ let image: UIImage = CoreAsset.exampleImage.image // Access from any target :)
299305
- [ ] Update `Backend`
300306
- [ ] Update `ShimmerUI`
301307
- [ ] Update Tuist docs ("Access Assets" section etc.)
308+
- [ ] Move version to xconfig file
302309

303310
## Extensions
304311

Targets/Core/Sources/Environment/Env.swift

+4-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
// Copyright © 2024 Md. Mahmudul Hasan Shohag. All rights reserved.
33
//
44

5+
import Alamofire
6+
import Foundation
7+
58
public struct Env {
6-
nonisolated(unsafe) public static let shared = Env()
9+
public nonisolated(unsafe) static let shared = Env()
710

811
public let environment: Environment
912

@@ -27,11 +30,4 @@ public struct Env {
2730

2831
#endif
2932
}
30-
31-
public let defaultSession = NetworkSession.getNetworkSession(
32-
hostUrl: Config.HOST_URL,
33-
httpAdditionalHeaders: [
34-
"Accept": "application/json"
35-
]
36-
)
3733
}

Targets/Core/Sources/Extensions/String+.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@ public extension String {
2828
let emailPredicate = NSPredicate(format: "SELF MATCHES %@", emailRegEx)
2929
return emailPredicate.evaluate(with: self)
3030
}
31-
31+
3232
func addingPercentEncodingForQueryParameter() -> String {
3333
return addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? ""
3434
}
35-
35+
3636
func toMarkdown() -> AttributedString {
3737
do {
38-
return try AttributedString(
39-
markdown: self,
40-
options: AttributedString.MarkdownParsingOptions(
41-
allowsExtendedAttributes: true,
42-
interpretedSyntax: .full
38+
return try AttributedString(
39+
markdown: self,
40+
options: AttributedString.MarkdownParsingOptions(
41+
allowsExtendedAttributes: true,
42+
interpretedSyntax: .full
43+
)
4344
)
44-
)
4545
} catch {
46-
print("Error parsing Markdown for string \(self): \(error)")
47-
return AttributedString(self)
46+
print("Error parsing Markdown for string \(self): \(error)")
47+
return AttributedString(self)
4848
}
49-
}
49+
}
5050
}
5151

52-
extension Optional where Wrapped == String {
52+
public extension Optional where Wrapped == String {
5353
/// Return `true` only if it is not `nil` or empty.
5454
var isBlank: Bool {
5555
return self?.isEmpty ?? true

Targets/Core/Sources/Extensions/URL+.swift

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import Foundation
66
import AVFoundation
7+
import SuperLog
78

89
public extension URL {
910
/// - Returns: The file size in KB.

Targets/Core/Sources/Navigation/Demo/NavigationDemoScreen.swift

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright © 2023 Md. Mahmudul Hasan Shohag. All rights reserved.
33
//
44

5+
import SuperLog
56
import SwiftUI
67

78
#if DEBUG

Targets/Core/Sources/Navigation/NavController.swift

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import Foundation
66
import SwiftUI
7+
import SuperLog
78

89
/// # Decision Documentation:
910
///

Targets/Core/Sources/Network/Extensions/Backend+.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import Foundation
66
import Moya
7+
import NetworkKit
78

89
public extension Backend {
910
convenience init(
@@ -13,7 +14,7 @@ public extension Backend {
1314
self.init(
1415
isStubbed: isUITestEnvironment ? true : isStubbed,
1516
stubBehavior: stubBehavior,
16-
session: Env.shared.defaultSession
17+
session: NetworkSession.default
1718
)
1819
}
1920
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Copyright © 2024 Md. Mahmudul Hasan Shohag. All rights reserved.
3+
//
4+
5+
import NetworkKit
6+
7+
public extension CertificateManager {
8+
static var `default`: CertificateManager {
9+
return CertificateManager(keys: [
10+
// [0x11, 0x22, 0xAA, 0xBB, ...],
11+
// [0x33, 0x44, 0xCC, 0xDD, ...]
12+
])
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Copyright © 2024 Md. Mahmudul Hasan Shohag. All rights reserved.
3+
//
4+
5+
import Alamofire
6+
import NetworkKit
7+
8+
public extension NetworkSession {
9+
static let `default` = NetworkSession.getNetworkSession(
10+
// Note: To do certificate pinning use the following commented code.
11+
// serverTrustManager: ServerTrustManager.default,
12+
httpAdditionalHeaders: [
13+
"Accept": "application/json",
14+
]
15+
)
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Copyright © 2024 Md. Mahmudul Hasan Shohag. All rights reserved.
3+
//
4+
5+
import Alamofire
6+
import Foundation
7+
import NetworkKit
8+
9+
public extension ServerTrustManager {
10+
static var `default`: ServerTrustManager {
11+
let domainName = URL(string: Env.shared.hostUrl)?.host ?? ""
12+
let evaluators: [String: ServerTrustEvaluating] = [
13+
domainName: PublicKeysTrustEvaluator(keys: CertificateManager.default.publicKeys),
14+
]
15+
16+
return ServerTrustManager(evaluators: evaluators)
17+
}
18+
}

Targets/Core/Sources/Network/GoRestAPI.swift

-51
This file was deleted.

Targets/Core/Sources/Network/STCertificateManager.swift

-43
This file was deleted.

0 commit comments

Comments
 (0)