Swiftpack.co - GSM-MSG/Miniature as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by GSM-MSG.
GSM-MSG/Miniature 1.3.1
📦 Repository pattern support library
⭐️ 2
🕓 39 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/GSM-MSG/Miniature.git", from: "1.3.1")

Miniature

Miniature can be used to handle loading data from both local and remote sources, as well as caching the data locally.

Document


Contents


Requirements

  • iOS 13.0+ / tvOS 13.0+ / watchOS 6.0+ / macOS 10.15+
  • Swift 5+

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation

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"))
]

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate Miniature into your project manually.


Usage

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)
    }
}

GitHub

link
Stars: 2
Last commit: 39 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Release Notes

1.3.1
39 weeks ago

Fixed

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