Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.
/ GTObservable Public archive

A simple wrapper to help observe property value changes in Swift

License

Notifications You must be signed in to change notification settings

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.