Miniature can be used to handle loading data from both local and remote sources, as well as caching the data locally.
Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
To integrate Miniature
into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:
dependencies: [
.package(url: "https://github.com/GSM-MSG/Miniature.git", .upToNextMajor(from: "1.1.1"))
]
If you prefer not to use either of the aforementioned dependency managers, you can integrate Miniature into your project manually.
struct Test {
var int = 0
func localData() -> Int {
return int
}
func remoteData() -> AnyPublisher<Int, Error> {
Just(2).delay(for: 2, scheduler: RunLoop.main)
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
}
mutating func updateLocal(int: Int) {
self.int = int
}
}
final class ViewController: UIViewController {
var bag = Set<AnyCancellable>()
override func viewDidLoad() {
super.viewDidLoad()
var test = Test()
await Miniature {
test.localData()
} onRemote: {
test.remoteData()
} refreshLocal: { value in
test.updateLocal(int: value)
}
.publish { status in
status.action { load in
print("LOAD", load)
} onCompleted: { complete in
print("COMPLETE", complete)
} onError: { err in
print(err)
}
}
CombineMiniature {
test.localData()
} onRemote: {
test.remoteData()
} refreshLocal: { value in
test.updateLocal(int: value)
}
.publish { status in
status.action { load in
print("LOAD", load)
} onCompleted: { complete in
print("COMPLETE", complete)
} onError: { err in
print(err)
}
}
.store(in: &bag)
}
}
link |
Stars: 2 |
Last commit: 39 weeks ago |
toAnyPublisher, toObservable을 사용했을 때 refreshLocal이 실행되지 않던 버그를 해결했습니다.
Full Changelog: https://github.com/GSM-MSG/Miniature/compare/1.3.0...1.3.1
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics