Swiftpack.co -  scalefocus/TwoWayBondage as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
scalefocus/TwoWayBondage
Two way binding library for Swift
.package(url: "https://github.com/scalefocus/TwoWayBondage.git", from: "2.2.0")

TwoWayBondage

Swift Version License Build Status CocoaPods Compatible Platform

Easy to use two way binding Library. Simpliest way to bind values from ViewModels to Views. Based on SimpleTwoWayBinding

Table of contents

Requirements

  • iOS 12.0+
  • Swift 5

Installation

TwoWayBondage is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'TwoWayBondage'

To get the full benefits import TwoWayBondage at the start of the source file:

import TwoWayBondage

Usage Example

Create ViewModel

All of the bindable properties should be declared as Observable in ViewModel.

import TwoWayBondage

struct ExampleViewModel {
    let name: Observable<String> = Observable<String>()
    let isBroccoliLover: Observable<Bool> = Observable<Bool>()
    let isIceCreamLover: Observable<Bool> = Observable<Bool>(true)
}

Create ViewController

To bind an Observable with UIControls and vise versa - bind or bindAndFire should be called in ViewController.

@IBOutlet private weak var nameTextField: UITextField!
@IBOutlet private weak var welcomeLabel: UILabel!
@IBOutlet private weak var iceCreamSwitch: UISwitch!

override viewDidLoad() {
    ...
    bindEvents()
}

private func bindEvents() {
    nameTextField.bind(viewModel.name)

    viewModel.name.bind { [weak self] name in
        self?.welcomeLabel.text = name
    }
    
    vieModel.isIceCreamLover.bindAndFire { [weak self] value in
        self?.iceCreamSwitch.setOn(value, animated: true)
    }
}

License

TwoWayBondage is available under the MIT license. See the LICENSE file for more info.

GitHub

link
Stars: 1
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics