explaingit

facebookarchive/kvocontroller

7,300Objective-CAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

An archived Objective-C library from Facebook that makes it safe and easy to watch for property changes in iOS and macOS apps, automatically cleaning up observers and supporting block callbacks instead of separate handler methods.

Mindmap

mindmap
  root((repo))
    What it does
      Safe KVO wrapper
      Block callbacks
      Auto cleanup
    Problems Solved
      Crash-prone removal
      Thread safety bugs
      Boilerplate methods
    Compatibility
      Objective-C
      Swift support
      iOS 6 plus
    Installation
      CocoaPods
      Carthage
      Manual drag-in
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Replace raw Apple KVO observation in an iOS app with block-based callbacks to reduce boilerplate and avoid crash-prone manual observer removal.

USE CASE 2

Safely observe a model object's properties from a view controller and have all observations cleaned up automatically when the view controller is deallocated.

USE CASE 3

Add thread-safe property observation to a Swift app by using KVOController with NSObject-inheriting classes and dynamic property annotations.

Tech stack

Objective-CSwiftCocoaPodsCarthageiOSmacOS

Getting it running

Difficulty · easy Time to first run · 30min

Project is archived, no further updates. Add via CocoaPods with `pod 'KVOController'`.

BSD license, use freely for any purpose including commercial apps, keep the copyright notice.

In plain English

KVOController is an Objective-C library originally built at Facebook that makes it easier and safer to watch for changes on iOS and macOS apps. It is now archived, meaning it receives no further updates, but the code is still available and usable. The problem it solves is about a built-in Apple pattern called key-value observing, which lets one part of an app automatically react when a property on another object changes, such as a clock view updating itself whenever a clock object's date property changes. Apple's original implementation of this pattern is known for being tricky: forgetting to remove an observer at the right time can crash the app, and using it across multiple threads has historically caused bugs. KVOController wraps that built-in system with a friendlier interface that handles these edge cases automatically. The main improvements are: you can use block callbacks instead of writing a separate method for every observation, the library never throws an exception when you remove an observer, and when the controller object itself is deallocated, all observations are cleaned up automatically without any extra code from you. It also includes thread-safety protections around a specific Apple bug related to observer cleanup. KVOController works in both Objective-C and Swift. For Swift there are two small requirements: the observing class must inherit from NSObject, and the property being watched must be marked as dynamic. The library works on iOS 6 and later, and OS X 10.7 and later. Installation is available through CocoaPods (add pod 'KVOController' to your Podfile), through Carthage, or by manually dragging two source files into your Xcode project. The project is released under a BSD license.

Copy-paste prompts

Prompt 1
I'm using KVOController in an iOS Objective-C app. Show me how to observe a property called 'progress' on a download model object and update a UIProgressView in the block callback.
Prompt 2
How do I use FBKVOController in Swift? Show me the minimum setup, which class must my observer inherit from, and how must I annotate the observed property?
Prompt 3
I'm replacing manual addObserver/removeObserver calls with KVOController. Walk me through converting an existing observeValueForKeyPath: method to the block-based KVOController API.
Prompt 4
KVOController is archived. What is the modern Apple-recommended replacement for KVO with block callbacks in Swift, and how does the migration from KVOController look?
Open on GitHub → Explain another repo

← facebookarchive on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.