Add debug logging to every view controller method during development without touching each class individually.
Write unit tests that verify a specific method was actually called, without subclassing or modifying the original class.
Attach analytics tracking to third-party library methods that you cannot subclass directly.
Intercept a method on a single object instance to temporarily change its behavior during a debugging session.
Conflicts with other code that uses Objective-C message forwarding, the author recommends limiting use to tests and debug builds only.
Aspects is an Objective-C library that lets you attach custom code to existing methods in your iOS or macOS app, without modifying those methods directly. You can specify whether your extra code runs before the original method, after it, or in place of it. This approach is called aspect-oriented programming, a pattern for handling concerns that touch many parts of a codebase at once, such as logging every method call or checking permissions before certain actions. The library works by intercepting Objective-C messages at runtime. When you register a hook, Aspects creates a dynamic subclass under the hood, similar to how the Key-Value Observing system works in Apple frameworks. You can attach hooks to an entire class or to a specific object instance. Calls are thread-safe, and each hook returns a token you can use to remove it later. Practical uses documented in the README include adding debug logging to view controllers, simplifying analytics tracking, verifying in unit tests that a method was actually called, and attaching behavior to classes from third-party libraries that you cannot subclass directly. There is a significant caveat stated clearly by the author: as of the time of the last update, the author does not recommend using Aspects in production code. The underlying mechanism for intercepting messages can conflict with other code that relies on the same message forwarding system. The documented recommended use is for test mocks and quick debugging during development, not for shipping apps. The library is written in Objective-C and the README shows usage examples in both Objective-C and Swift.
← steipete on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.