Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/heroesofcode/datalife
- Owner: heroesofcode
- License: mit
- Created: 2020-08-30T01:33:14.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-05-21T02:57:48.000Z (6 months ago)
- Last Synced: 2024-05-21T03:53:15.181Z (6 months ago)
- Topics: datalife, ios, macos, swift-package-manager, tvos
- Language: Swift
- Homepage:
- Size: 276 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
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 DataLifefinal 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 UIKitfinal 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.
## LicenseDataLife is released under the MIT license. See [LICENSE](https://github.com/heroesofcode/DataLife/blob/master/LICENSE) for details.