All Projects → manishkkatoch → Simpletwowaybindingios

manishkkatoch / Simpletwowaybindingios

Licence: mit
An ultra light, ultra simple two way binding library for IOS and Swift.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Simpletwowaybindingios

Mvvm Reddit
A companion project for our blog post on better Android software development using MVVM with RxJava.
Stars: ✭ 106 (-28.86%)
Mutual labels:  mvvm, mobile-development
Ribs
Uber's cross-platform mobile architecture framework.
Stars: ✭ 6,641 (+4357.05%)
Mutual labels:  mvvm, mobile-development
Webcell
Web Components engine based on JSX & TypeScript
Stars: ✭ 139 (-6.71%)
Mutual labels:  mvvm
Android Vmlib
VMLib is an Android framework based on Android Jetpack, easy to use, desinged for fast development. Embrace the new way devloping Android :)
Stars: ✭ 146 (-2.01%)
Mutual labels:  mvvm
Androidmodulararchiteture
✔️ Android组件化架构,支持组件代码完全隔离/组件循环依赖/便捷集成调试/快速接入,组件内基于 mvvm结构,组件提供高度服用的模块可直接使用,采用 wanAndroid api进行迭代开发。Android componentized architecture, support component code complete isolation / component circular dependency / convenient integrated debugging / fast access, component based mvvm structure, iterative development using wanAndroid api
Stars: ✭ 144 (-3.36%)
Mutual labels:  mvvm
Flutter animated background
Animated Backgrounds for Flutter.
Stars: ✭ 140 (-6.04%)
Mutual labels:  mobile-development
Xamu Infrastructure
Extensions, MVVM classes, behaviors and other misc. useful code bits from Xamarin University
Stars: ✭ 144 (-3.36%)
Mutual labels:  mvvm
Kaiui
React component library for KaiOS apps
Stars: ✭ 139 (-6.71%)
Mutual labels:  mobile-development
Mvvmrxjavaretrofitsample
MVVM RxJava Retrofit Sample
Stars: ✭ 148 (-0.67%)
Mutual labels:  mvvm
Beaver
Android MVVM + Dagger 2 (Hilt) + JetPack project template
Stars: ✭ 144 (-3.36%)
Mutual labels:  mvvm
Mediapipe
Cross-platform, customizable ML solutions for live and streaming media.
Stars: ✭ 15,338 (+10193.96%)
Mutual labels:  mobile-development
Android Template
Android app starter template
Stars: ✭ 141 (-5.37%)
Mutual labels:  mvvm
Foodium
It simply loads Posts data from API and stores it in persistence storage (i.e. SQLite Database). Posts will be always loaded from local database. Remote data (from API) and Local data is always synchronized.
Stars: ✭ 1,940 (+1202.01%)
Mutual labels:  mvvm
Monkey
Monkey is an unofficial GitHub client for iOS,to show the rank of coders and repositories.
Stars: ✭ 1,765 (+1084.56%)
Mutual labels:  mvvm
Unio
🔄 KeyPath based Unidirectional Input / Output framework with RxSwift.
Stars: ✭ 139 (-6.71%)
Mutual labels:  mvvm
Ktarmor Mvvm
👻 Android快速开发框架, KtArmor 寓意着 为Android 赋予战斗装甲, 方便开发者快速进行Android 开发。
Stars: ✭ 148 (-0.67%)
Mutual labels:  mvvm
Android Clean Architecture Mvvm Dagger Rx
Implemented by Clean Architecture, Dagger2, MVVM, LiveData, RX, Retrofit2, Room, Anko
Stars: ✭ 138 (-7.38%)
Mutual labels:  mvvm
Popularmovies
🎥 Movie discovery app showcasing Android best practices with Google's recommended architecture: MVVM + Repository + Offline support + Android Architecture Components + Paging library & Retrofit2.
Stars: ✭ 142 (-4.7%)
Mutual labels:  mvvm
My Medium Articles
List of my blog posts in the Medium
Stars: ✭ 143 (-4.03%)
Mutual labels:  mobile-development
Flutter Ui Reality
UI to Reality? With flutter.
Stars: ✭ 149 (+0%)
Mutual labels:  mobile-development

update: 08/24/2019

This repository was created for demonstration purpose rather than for consumption. However, given the feedback and usage of this repository, I will start maintaining it here-on and priortize fixing/implementing raised issues.

SimpleTwoWayBinding for iOS

Version License Platform

The Need

MVVM? why not MVC that Apple recommends? Android does MVP great right? How about the cool VIPER pattern? I believe great efforts have already been put to explain what each pattern brings to the table and so the idea here is not to add to the debate but merely build on top of the opinion I have already formed: MVVM is the way to go.

As a quick primer to what MVVM is, it is a design pattern whereby the ViewModel mediates between a data providing Model and View which displays the data provided like shown below:

mvvm diag

in iOS, View is essentially a ViewController and ViewModel is an object (a structure) which provides exact data for the view to render.

This provides a loosely coupled architecture which is maintainable ( very thin view controllers ) and testable (ViewModel abstracts out the UI and hence is easily testable)

There is still a caveat though: classic MVVM allows for single responsibility principle easily (and beautifully) in case of models as domain models. However, in case of anaemic models ( which is generally the case when you have well written REST APIs), one would also need another Mediator or Presenter which facilitates data and navigation flow.

Now, View Model has responsibility to update View as well as get updates from View regarding the changes made by the user. This can be achieved by minimum code using bi-directional data binding. But … iOS has no two way binding mechanism available out of the box!

Luckily we have reactive libraries like RxSwift, RxCocoa but they are too heavy considering two way binding is a very tiny part of the Reactive Programming paradigm. SimpleTwoWayBinding strives to provide just two way binding, in a simple unassuming way!

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Creating ViewModel

import SimpleTwoWayBinding

struct FormViewModel {
    let name: Observable<String> = Observable()
    let companyName: Observable<String> = Observable()
    let yearsOfExperience: Observable<Double> = Observable()
    let isCurrentEmployer: Observable<Bool> = Observable(false)
    let approxSalary: Observable<Float> = Observable()
    let comments: Observable<String> = Observable()
}

The properties you want to be "bindable" to the View should be declared as Observable.

Binding to ViewController

class ViewController: UIViewController {

    @IBOutlet weak var nameField: UITextField!
    @IBOutlet weak var companyField: UITextField!
    @IBOutlet weak var isCurrentEmployerSwitch: UISwitch!
    @IBOutlet weak var yearsOfExperienceStepper: UIStepper!
    @IBOutlet weak var salaryRangeSlider: UISlider!
    @IBOutlet weak var selectedSalaryRangeLabel: UILabel!
    @IBOutlet weak var selectedYearsOfExperienceLabel: UILabel!
    
    var viewModel: FormViewModel!
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationItem.title = "Survey Form"
        setupBindings()
    }
    
    func setupBindings() {
        nameField.bind(with: viewModel.name)
        companyField.bind(with: viewModel.companyName)
        isCurrentEmployerSwitch.bind(with: viewModel.isCurrentEmployer)
        yearsOfExperienceStepper.bind(with: viewModel.yearsOfExperience)
        salaryRangeSlider.bind(with: viewModel.approxSalary)
      
        selectedSalaryRangeLabel.observe(for: viewModel.approxSalary) {
            [unowned self](_) in
            self.selectedSalaryRangeLabel.text =
                self.viewModel.getSalaryString()
        }
        
        selectedYearsOfExperienceLabel.observe(for: viewModel.yearsOfExperience) {
            [unowned self](_) in
            self.selectedYearsOfExperienceLabel.text =
                self.viewModel.getExperienceString()
        }
    }
}

The bind method on the UIControl orchestrates the two way binding with the Observable. That's all code that is needed to get the form working. See below screen shot.

working sample

Installation

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

pod 'SimpleTwoWayBinding'

Author

Manish Katoch, [email protected]

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].