Latest 0.2.0
Homepage https://github.com/timbodeit/ObserverManager
License MIT
Platforms ios 8.0, osx 10.10, watchos 2.0, requires ARC
Authors

CI Status
Version
License
Platform

Closure Support and automatic deregistering for Key Value Observing in Swift.

Requirements

This version of ObserverManager is meant to be used with Swift 3.0

For Swift 2 use Version 0.1.0

Usage

import Foundation
import ObserverManager

class SomeObservingClass {

    let foo: Foo
    let observerManager = ObserverManager()

    init(foo: Foo) {
        self.foo = foo

        observerManager.registerObserver(object: foo, keyPath: "bar") { bar in
            // Do stuff
            [...]
        }
    }
}

Interface

/**
A class that can be used to sign up for Key-Value Observing by
passing a Swift closure.

Every object, that uses KVO should have its own NotificationManager.
All observers are automatically deregistered when the object is deallocated.
*/
public class ObserverManager : NSObject {

/**
Registers a new observer for a given object and keypath.

- parameter object:  The object to observe
- parameter keyPath: The keyPath to observe
- parameter block:   The block that is called when the value changed. Gets called with the new value.
*/
open func registerObserver(object: NSObject, keyPath: String, block: @escaping (_ value: NSObject) -> ())

/**
Removes all observers that observe the given keypath on the given object.
*/
open func deregisterObservers(object: NSObject, keyPath: String)

/**
Removes all observers that observe any keypath on the given object.
*/
open func deregisterObservers(object: NSObject)

/**
Removes all observers that observe any keypath on any object.
*/
open func deregisterAllObservers()

}

Installation

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

pod "ObserverManager"

Author

Tim Bodeit, [email protected]

License

ObserverManager is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "ObserverManager",
    "version": "0.2.0",
    "summary": "Simple KVO in Swift",
    "description": "Closure Support and automatic deregistering for Key Value Observing in Swift",
    "homepage": "https://github.com/timbodeit/ObserverManager",
    "license": "MIT",
    "authors": {
        "Tim Bodeit": "[email protected]"
    },
    "source": {
        "git": "https://github.com/timbodeit/ObserverManager.git",
        "tag": "0.2.0"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "watchos": "2.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This