Skip to content
This repository was archived by the owner on Nov 30, 2025. It is now read-only.

heroesofcode/DataLife

Repository files navigation

Warning

This project is no longer maintained.
If you want to continue using DataLife, feel free to fork the repository and maintain your own version.

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

  •  
  •  
  •