Skip to content

gametimesf/GTObservable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GTObservable

Use GTObservable as a wrapper around your propeties making it easy to subscribe to their changes.

Installation

Carthage compatible

Carthage

github "gametimesf/GTObservable" == 1.1

To use, simply:

    var observableLoggedIn = GTObservable<Bool>(false)

    // observe all future changes 
    observableLoggedIn.observe(self) { [weak self] update in
      print("your value changed from \(update.oldValue) to \(update.newValue)")
    }

    // observe all future changes AND fire with the current value at observation time  
    observableLoggedIn.fireThenObserve(self) { [weak self] _ in }
    
    // update the value 
    observableLoggedIn.value = true

Observers are safe, and will automatically unsubscribe when your observing object is deallocated.