I created an Observable class that allows me to subscribe to a wrapped value. The implementation looks like this:class Observable<ValueType> {    typealias DidChangeHandler = (oldValue: ValueType?, newValue: ValueType) -> ()    // MARK: Properties    var value : ValueType {        didSet {            for (owner, handlers) in self._observers {                for handler in handlers {                    handler(oldValue: oldValue, newValue: value)                }            }        }    }    // MARK: Initializers    init(_ value: ValueType) {        self.value = value    }    // MARK: Methods    func addObserverForOwner(owner: AnyObject, triggerImmediately: Bool, handler: DidChangeHandler) {        if let index = self._indexOfOwner(owner) {            // since the owner exists, add the handler to the existing array            self._observers[index].handlers.append(handler)        }        else {            // since the owner does not already exist, add a new tuple with the            // owner and an array with the handler            self._observers.append(owner: owner, handlers: [handler])        }        if (triggerImmediately) {            handler(oldValue: nil, newValue: self.value)        }    }    func removeObserversForOwner(owner: AnyObject) {        if let index = self._indexOfOwner(owner) {            self._observers.removeAtIndex(index)        }    }    // MARK: Private Properties    private var _observers: [(owner: AnyObject, handlers: [DidChangeHandler])] = []    // MARK: Private Methods    private func _indexOfOwner(owner: AnyObject) -> Int? {        var index: Int = 0        for (possibleOwner, handlers) in self._observers {            if possibleOwner === owner {                return index            }            index++        }        return nil    }}This allows me to create a variable and observer it as follows:var observableString = Observable<String>(String)observableString.addObserverForOwner(self, triggerImmediately: false) {    (oldValue, newValue) in    // ...}I think this is most useful to use for properties on classes.However, there are a few things that I don't like:Requires manually unobserving even if the owner is deallocedtriggerImmediately seems kind of verboseoldValue has to be an optional because in the triggerImmediately case there is no old valueMostly I am looking for any ideas on ways to improve the usability of this interface, but I am open to any ways to improve the code.Update 08/02/2014I actually figured out a way to not require manually unobserving if the owner is deallocated. It isn't perfect, but it does work. Basically I created a WeakWrapper class that makes a weak reference to a wrapped value. This allows Observable to keep an array of weak references instead of strong references to observers. The reference will be set to nil when the observer is dealloced so I can clean them up the next time the observable is triggered. The negative part of it is that the handlers are not removed until the next time the observable is triggered.To see the new code, including changes suggested by @nhgrif below, you can visit my github repository.
Usability of this Observable class
swift