Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any data binding mechanism available for iOS?

Tags:

In .NET I just do something like DataForm.Source = Object and then magic happens. Platform routes data changes from ui fileds to object properties, does validation and so on. Can I do something similar with Cocoa Touch and CoreData objects?

like image 345
fspirit Avatar asked Sep 28 '10 13:09

fspirit


People also ask

What is data binding in IOS?

What is Data Binding? Data Binding is how the app's view and data are bound. In MVVM, we achieve this by binding the View Model (the data) and the View Controller (the view). Though we always connect the view model and the view in MVVM, there are several different techniques on how one can do this.

What is a data binding mechanism?

Data binding is the process that establishes a connection between the application UI and business logic. If the binding has correct settings and the data provides proper notifications, then whenever the data changes its value, the elements that are bound to the data reflect changes automatically.

What are MVVM bindings?

Edit. Data binding is the key technology that MVVM relies on, to link Views with their View-Models. Data binding provides and maintains the automated Two-Way connection between View and ViewModel. A good understanding of data binding is essential for every MVVM developer.


2 Answers

The closest thing in Cocoa is 'Key-Value Observing'. In the desktop Cocoa framework you can use bindings to hook user interface elements up to underlying objects so that changes in the objects or UI elements are reflected in the other.

Whilst Cocoa on iOS doesn't have this sort of UI bindings, you can still use 'Key-Value Observing' to synchronise changes in the data model with UI elements as described here:

http://developer.apple.com/library/iOS/#documentation/General/Conceptual/Devpedia-CocoaApp/KVO.html

like image 143
Jake Avatar answered Oct 08 '22 03:10

Jake


I wrote a little open-source library that provides some simple data-binding functionality. It's basically just a wrapper around key-value observing (KVO).

  • http://github.com/kristopherjohnson/KJSimpleBinding

There are a few other similar libraries on GitHub:

  • http://github.com/dewind/KeyPathBindings
  • http://github.com/jonsterling/Observe
  • http://github.com/mruegenberg/objc-simple-bindings
  • http://github.com/zeasy/EasyBinding
like image 22
Kristopher Johnson Avatar answered Oct 08 '22 02:10

Kristopher Johnson