Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/heroesofcode/datalife

DataLife is an observable data storage class written in Swift
https://github.com/heroesofcode/datalife

datalife ios macos swift-package-manager tvos

Last synced: 1 day ago
JSON representation

DataLife is an observable data storage class written in Swift

Awesome Lists containing this project

README

        



[![CI](https://github.com/heroesofcode/DataLife/actions/workflows/CI.yml/badge.svg)](https://github.com/heroesofcode/DataLife/actions/workflows/CI.yml)
[![SPM compatible](https://img.shields.io/badge/SPM-compatible-brightgreen)](https://swift.org/package-manager/)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fheroesofcode%2FDataLife%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/heroesofcode/DataLife)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fheroesofcode%2FDataLife%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/heroesofcode/DataLife)
[![GitHub](https://img.shields.io/github/license/heroesofcode/DataLife)](https://github.com/joaolfp/DataLife/blob/master/LICENSE)

## Overview

DataLife is an observable data storage class

## Usage

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

```swift
import DataLife

final class ViewModel: DataLifeViewModel {

var myName = DataLife()

func fetchMyName() {
myName.value = "Darth Vader"
}

}
```
- In the ViewController you will call the variable that was created in the ViewModel that will be observed.

``` swift
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](https://github.com/heroesofcode/DataLife/tree/master/Example)

## Installation

### [Swift Package Manager (SPM)](https://swift.org/package-manager)

```swift
import PackageDescription
let package = Package(
name: "",
dependencies: [
.package(url: "https://github.com/heroesofcode/DataLife", .upToNextMajor(from: "2.0.0"))
],
targets: [
.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](https://github.com/heroesofcode/DataLife/blob/master/LICENSE) for details.