gitmyhub

KVOController

Objective-C ★ 7.3k updated 6y ago ▣ archived

Simple, modern, thread-safe key-value observing for iOS and OS X.

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.

Objective-CSwiftCocoaPodsCarthageiOSmacOSsetup: easycomplexity 2/5

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.

Where it fits