Files
Felix Mau ed722cb70d * updated pods
* added `Observable` pod as dependency for `GradientLoadingBar`
2018-08-18 13:22:34 +02:00
..
2018-08-18 13:22:34 +02:00
2018-08-18 13:22:34 +02:00
2018-08-18 13:22:34 +02:00

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'

Suggestions or feedback?

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