alecgorge / Observable

The easiest way to observe values in Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Observable

Observable is the easiest way to observe values in Swift.

How to

Create an Observable

var position = Observable(CGPoint.zero)

Add an observer

position.observe { p in
    // handle new position
}

Change the value

position.value = p

Memory management

For a single observer you can store the returned Disposable to a variable

disposable = position.observe { p in

For multiple observers you can add the disposable to a Disposal variable

position.observe { }.add(to: &disposal)

And always weakify self when referencing self inside your observer

position.observe { [weak self] position in

Installation

CocoaPods

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

pod 'Observable'

Carthage

Observable is available through Carthage. To install it, simply add the following line to your Cartfile:

github "roberthein/Observable" "master"

Suggestions or feedback?

Feel free to create a pull request, open an issue or find me on Twitter.

About

The easiest way to observe values in Swift.

License:MIT License


Languages

Language:Swift 88.5%Language:Ruby 11.5%