Latest 1.1
License MIT
Platforms ios 8.0

Language: Swift 3
Platform: iOS 8+
Cocoapods compatible
License: MIT

An easy way in Swift to use KVO, prefer block.

If your have any question, you can email me([email protected]) or leave message.


  • iOS 8.0+
  • Xcode 7.0 or above


KVO ZHObserver way

  • add observe
    obj.zh_observe("your path", options: .New) { (object, values, change) in
        // your code
* remove observe
    obj.zh_unobserve("your path")     // remove specified observed path, and do not wrong about "your path" has oberserved
    obj.zh_unobserve(nil)          // remove all observed path

Instead of the familiar syntax like:

    obj.addObserver(observerObj, forKeyPath: "your path", options: .New, context: &yourContext)


    override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
        guard context == &yourContext else {
            super.observeValueForKeyPath(keyPath, ofObject: object, change: change, context: context)

        if keyPath == ""your path" {
            // your code


    obj.removeObserver("your path")     // you have to care "your path" if not observed it will crash



CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate ChameleonSwift into your Xcode project using CocoaPods, specify it in your Podfile:

source ''
platform :ios, '8.0'

pod 'ZHObserverSwift'

If you use swift 2, use pod ‘ZHObserverSwift’ , ‘~> 0.1’

Then, run the following command:

$ pod install

You should open the {Project}.xcworkspace instead of the {Project}.xcodeproj after you installed anything from CocoaPods.


github "zhangbozhb/ZHObserverSwift"

Latest podspec

    "name": "ZHObserverSwift",
    "version": "1.1",
    "summary": "An easy way in Swift to use KVO, prefer block.",
    "description": "A wrapper for KVO. It's easy to use and uses block to handle changes.",
    "homepage": "",
    "license": {
        "type": "MIT"
    "authors": {
        "travel": "[email protected]"
    "social_media_url": "",
    "platforms": {
        "ios": "8.0"
    "source": {
        "git": "",
        "tag": "1.1"
    "source_files": [
    "exclude_files": "Sources/Exclude",
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "3.0"
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This