Interpose
final public class Interpose
Interpose is a modern library to swizzle elegantly in Swift.
Methods are hooked via replacing the implementation, instead of the usual exchange. Supports both swizzling classes and individual objects.
-
Stores swizzle hooks and executes them at once.
Declaration
Swift
public let `class`: AnyClass
-
Lists all hooks for the current interpose class object.
Declaration
Swift
public private(set) var hooks: [AnyHook] { get }
-
If Interposing is object-based, this is set.
Declaration
Swift
public let object: AnyObject?
-
Initializes an instance of Interpose for a specific class. If
builder
is present,apply()
is automatically called.Declaration
Swift
public init(_ class: AnyClass, builder: ((Interpose) throws -> Void)? = nil) throws
-
Initialize with a single object to interpose.
Declaration
Swift
public init(_ object: NSObject, builder: ((Interpose) throws -> Void)? = nil) throws
-
Hook an
@objc dynamic
instance method via selector name on the current class.Declaration
Swift
@discardableResult public func hook<MethodSignature, HookSignature>( _ selName: String, methodSignature: MethodSignature.Type = MethodSignature.self, hookSignature: HookSignature.Type = HookSignature.self, _ implementation: (TypedHook<MethodSignature, HookSignature>) -> HookSignature?) throws -> TypedHook<MethodSignature, HookSignature>
-
Hook an
@objc dynamic
instance method via selector on the current class.Declaration
Swift
@discardableResult public func hook<MethodSignature, HookSignature> ( _ selector: Selector, methodSignature: MethodSignature.Type = MethodSignature.self, hookSignature: HookSignature.Type = HookSignature.self, _ implementation: (TypedHook<MethodSignature, HookSignature>) -> HookSignature?) throws -> TypedHook<MethodSignature, HookSignature>
-
Prepares a hook, but does not call apply immediately.
Declaration
Swift
@discardableResult public func prepareHook<MethodSignature, HookSignature> ( _ selector: Selector, methodSignature: MethodSignature.Type = MethodSignature.self, hookSignature: HookSignature.Type = HookSignature.self, _ implementation: (TypedHook<MethodSignature, HookSignature>) -> HookSignature?) throws -> TypedHook<MethodSignature, HookSignature>
-
Apply all stored hooks.
Declaration
Swift
@discardableResult public func apply(_ hook: ((Interpose) throws -> Void)? = nil) throws -> Interpose
-
Revert all stored hooks.
Declaration
Swift
@discardableResult public func revert(_ hook: ((Interpose) throws -> Void)? = nil) throws -> Interpose
-
A hook to an instance method and stores both the original and new implementation.
See moreDeclaration
-
Logging uses print and is minimal.
Declaration
Swift
public static var isLoggingEnabled: Bool
-
A hook to an instance method of a single object, stores both the original and new implementation. Think about: Multiple hooks for one object
See moreDeclaration
-
Interpose a class once available. Class is passed via
classParts
string array.Declaration
-
Interpose a class once available. Class is passed via
classParts
string array, with completion handler.Declaration
-
Interpose a class once available. Class is passed via
className
string.Declaration
-
Interpose a class once available. Class is passed via
className
string, with completion handler.Declaration
-
Helper that stores hooks to a specific class and executes them once the class becomes available.
Declaration
Swift
public struct Waiter