Swiftpack.co - heroesofcode/DataLife as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by heroesofcode.
heroesofcode/DataLife v1.0.5
DataLife is an observable data storage class written in Swift
⭐️ 5
🕓 2 years ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/heroesofcode/DataLife.git", from: "v1.0.5")

CI codecov SPM compatible GitHub

Overview

DataLife is an observable data storage class

Usage

  • In ViewModel inherit from DataLifeViewModel and create a variable that will be the result value.
import DataLife

final class ViewModel: DataLifeViewModel {
    
    var myName = DataLife<String>()
    
    func fetchMyName() {
        myName.value = "Darth Vader"
    }
    
}
  • In the ViewController you will call the variable that was created in the ViewModel that will be observed.
import UIKit

final class ViewController: UIViewController {
    
    @IBOutlet weak var nameLabel: UILabel!
    
    private let viewModel = ViewModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupState()
        setupFetchMyName()
    }

    private func setupFetchMyName() {
        viewModel.fetchMyName()
    }
    
    private func setupState() {
        viewModel.myName.observer(viewModel) { [weak self] name in
            self?.nameLabel.text = name
        }
    }
}

Installation

Swift Package Manager (SPM)

import PackageDescription
let package = Package(
    name: "<Your Product Name>",
    dependencies: [
       .package(url: "https://github.com/heroesofcode/DataLife", .upToNextMajor(from: "1.4.0"))
    ],
    targets: [
        .target(
            name: "<Your Target Name>",
            dependencies: ["DataLife"]),
    ]
)

Contributing

To contribute, just fork this project and then open a pull request, feel free to contribute, bring ideas and raise any problem in the issue tab.

Contributors

License

DataLife is released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 5
Last commit: 5 days ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

23 weeks ago

Requirements

  • Support for CocoaPods and Carthage has been obsoleted. No new releases will be available on those platforms, starting with 1.3.0. Please use the Swift Package Manager to depend on DataLife.
  • DataLife now requires iOS 12+, macOS 10.13+ and tvOS 12+.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics