Skip to content

heroesofcode/DataLife

Repository files navigation

CI 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.addObserver(viewModel) { [weak self] name in
            self?.nameLabel.text = name
        }
    }
}

Demo

You see the demo here

Installation

import PackageDescription
let package = Package(
    name: "<Your Product Name>",
    dependencies: [
       .package(url: "https://github.com/heroesofcode/DataLife", .upToNextMajor(from: "2.0.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.

License

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

About

DataLife is an observable data storage class written in Swift

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •