-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24f3526
commit b30b131
Showing
15 changed files
with
308 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/config/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
8 changes: 8 additions & 0 deletions
8
.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// swift-tools-version: 5.7 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Core", | ||
platforms: [.iOS(.v15), .macOS(.v10_15)], | ||
products: [ | ||
// Products define the executables and libraries a package produces, and make them visible to other packages. | ||
.library( | ||
name: "Core", | ||
targets: ["Core"]), | ||
], | ||
dependencies: [ | ||
// Dependencies declare other packages that this package depends on. | ||
// .package(url: /* package url */, from: "1.0.0"), | ||
.package(name: "Realm", url: "https://github.com/realm/realm-cocoa.git", from: "10.5.2") | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages this package depends on. | ||
.target( | ||
name: "Core", | ||
dependencies: [ | ||
.product(name: "RealmSwift", package: "Realm"), | ||
] | ||
), | ||
.testTarget( | ||
name: "CoreTests", | ||
dependencies: ["Core"]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Iqbal Nur Haq on 03/01/23. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
public protocol DataSource { | ||
associatedtype Request | ||
associatedtype Response | ||
|
||
func execute(request: Request?) -> AnyPublisher<Response, Error> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Iqbal Nur Haq on 03/01/23. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
public protocol LocaleDataSource { | ||
associatedtype Request | ||
associatedtype Response | ||
|
||
func list(request: Request?) -> AnyPublisher<[Response], Error> | ||
func add(entities: [Response]) -> AnyPublisher<Bool, Error> | ||
func addOne(entity: Response) -> AnyPublisher<Bool, Error> | ||
func get(id: String?) -> AnyPublisher<Response, Error> | ||
func update(id: Int, entity: Response) -> AnyPublisher<Bool, Error> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Iqbal Nur Haq on 03/01/23. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
public protocol Repository { | ||
associatedtype Request | ||
associatedtype Response | ||
|
||
func execute(request: Request?) -> AnyPublisher<Response, Error> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Iqbal Nur Haq on 03/01/23. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
public struct Interactor<Request, Response, R: Repository>: UseCase | ||
where R.Request == Request, R.Response == Response { | ||
|
||
private let _repository: R | ||
|
||
public init(repository: R) { | ||
_repository = repository | ||
} | ||
|
||
public func execute(request: Request?) -> AnyPublisher<Response, Error> { | ||
_repository.execute(request: request) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Iqbal Nur Haq on 03/01/23. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
public protocol UseCase { | ||
associatedtype Request | ||
associatedtype Response | ||
|
||
func execute(request: Request?) -> AnyPublisher<Response, Error> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Iqbal Nur Haq on 03/01/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum URLError: LocalizedError { | ||
case invalidRequest | ||
case invalidResponse | ||
case addressUnreachable(URL) | ||
case custom(String) | ||
|
||
public var errorDescription: String? { | ||
switch self { | ||
case .invalidRequest: return "Request is null." | ||
case .invalidResponse: return "The server responded with garbage." | ||
case .addressUnreachable(let url): return "\(url.absoluteString) is unreachable." | ||
case .custom(let message): return "\(message)" | ||
} | ||
} | ||
} | ||
|
||
public enum DataBaseError: LocalizedError { | ||
case invalidInstance | ||
case requestFailed | ||
|
||
public var errorDescription: String? { | ||
switch self { | ||
case .invalidInstance: return "Database can't instance." | ||
case .requestFailed: return "Your request failed." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Iqbal Nur Haq on 03/01/23. | ||
// | ||
|
||
import Foundation | ||
import RealmSwift | ||
|
||
extension Results { | ||
public func toArray<T>(ofType: T.Type) -> [T] { | ||
var array = [T]() | ||
for index in 0 ..< count { | ||
if let result = self[index] as? T { | ||
array.append(result) | ||
} | ||
} | ||
|
||
return array | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Iqbal Nur Haq on 04/01/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol Mapper { | ||
associatedtype Request | ||
associatedtype Response | ||
associatedtype Entity | ||
associatedtype Domain | ||
|
||
func transformResponseToEntity(request: Request?, response: Response) -> Entity | ||
func transformEntityToDomain(entity: Entity) -> Domain | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Iqbal Nur Haq on 05/01/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import Combine | ||
|
||
public class Presenter<Request, Response, Interactor: UseCase>: ObservableObject | ||
where | ||
Interactor.Request == Request, | ||
Interactor.Response == Response { | ||
|
||
private var cancellables: Set<AnyCancellable> = [] | ||
private let _useCase: Interactor | ||
|
||
@Published public var item: Response? | ||
@Published public var errorMessage: String = "" | ||
@Published public var isLoading: Bool = false | ||
@Published public var isError: Bool = false | ||
|
||
public init(useCase: Interactor){ | ||
_useCase = useCase | ||
} | ||
|
||
public func execute(request: Request?) { | ||
isLoading = true | ||
_useCase.execute(request: request) | ||
.receive(on: RunLoop.main) | ||
.sink(receiveCompletion: { completion in | ||
switch completion { | ||
case .failure(let error): | ||
self.errorMessage = error.localizedDescription | ||
self.isError = true | ||
self.isLoading = false | ||
case .finished: | ||
self.isLoading = false | ||
} | ||
}, receiveValue: { item in | ||
self.item = item | ||
}) | ||
.store(in: &cancellables) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Iqbal Nur Haq on 11/01/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public class Prefs | ||
{ | ||
private let defaults = UserDefaults.standard | ||
|
||
private let keyAccessTokenPrefs = "tokenPrefs" | ||
|
||
public var accessTokenPrefs: String { | ||
set { | ||
defaults.setValue(newValue, forKey: keyAccessTokenPrefs) | ||
} | ||
get { | ||
return defaults.string(forKey: keyAccessTokenPrefs) ?? "" | ||
} | ||
} | ||
|
||
public class var shared: Prefs { | ||
struct Static { | ||
static let instance = Prefs() | ||
} | ||
|
||
return Static.instance | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import XCTest | ||
@testable import Core | ||
|
||
final class CoreTests: XCTestCase { | ||
func testExample() throws { | ||
// This is an example of a functional test case. | ||
// Use XCTAssert and related functions to verify your tests produce the correct | ||
// results. | ||
XCTAssertEqual(Core().text, "Hello, World!") | ||
} | ||
} |