ObjectiveKit
ObjectiveKit provides a Swift friendly API for a set of powerful Objective C runtime functions.
Usage
To use ObjectiveKit:
Import ObjectiveKit at the top of your Swift file:
The next step is to create an ObjectiveClass object typed for the class you want to modify or introspect:
If using ObjectiveKit on a custom Swift class, make sure that it inherits at some point from NSObject and that it is exposed to the Objective C runtime using the @objc flag.
Introspection
You can learn more about classes at runtime with these handy introspection methods:
Modifying classes at runtime
Add a pre-existing selector from another class to your ObjectiveClass:
Add a custom method by providing the implementation with a closure:
ObjectiveKit also supports exchanging selectors in the same class:
Creating classes at runtime
Lastly, you can also create a custom ObjC class at runtime:
Setting up
Setting up with CocoaPods
Setting up with Carthage
Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.
You can install Carthage with Homebrew using the following command:
To integrate ObjectiveKit into your Xcode project using Carthage, specify it in your Cartfile
: