Swiftpack.co - Package - joaolfp/DataLife

Swift Version Cocoapods compatible SPM compatible License

Overview

DataLife is an observable data storage class

How to use?

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

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

class ViewController: UIViewController {
    
    private let viewModel = ViewModel()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupState()
        setupFetchMyName()
    }

    private func setupFetchMyName() {
        viewModel.fetchMyName()
    }
    
    private func setupState() {
        viewModel.myName.observer(viewModel) { name in
            print(name)
        }
    }
}

Installation

Swift Package Manager

import DataLife
dependencies: [
    .package(url: "https://github.com/joaolfp/DataLife.git", .upToNextMajor(from: "1.0.4"))
]

Cocoapods

import DataLife
target '<Your Target Name>' do
  pod 'DataLife'
end
$ pod install

Author

Coded by João Lucas

License

MIT License

Copyright (c) 2020 João Lucas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
© 2020 GitHub, Inc.

Github

link
Stars: 0

Dependencies

Used By

Total: 0

Releases

Fix in constructor in DataLifeViewModel - 2020-08-30 02:39:40

  • Fix in constructor in DataLifeViewModel

Setup DataLifeViewModel - 2020-08-30 02:23:37

  • Setup DataLifeViewModel

Fix DataLife - 2020-08-30 02:19:32

  • Fix method observer in DataLife

Fix DataLife - 2020-08-30 02:06:16

  • Fix DataLife

Init DataLife - 2020-08-30 01:53:09

  • Initialize DataLife