ClassHookProtocol

public protocol ClassHookProtocol : AnyObject, AnyHook

The protocol to which class hooks conform. Do not conform to this directly; use ClassHook.

  • The type of the target. Specify this via the generic argument on ClassHook.

    This type must be either the target’s own class or a class in its inheritance chain.

    Declaration

    Swift

    associatedtype Target : AnyObject
  • The name of the target class, or the empty string to use Target.self.

    This class must be Target or a subclass of Target. Defaults to an empty string.

    Warning

    Do not attempt to access target in the getter for this property, as that will lead to infinite recursion.

    Declaration

    Swift

    static var targetName: String { get }
  • If this is not .none, it indicates that this hook creates a subclass.

    The created subclass can be accessed via the static target property. The default value is .none.

    This property is implemented by creating a new class pair on top of the original target, when the property is not .none.

    Warning

    Do not attempt to access target in the getter for this property, as that will lead to infinite recursion.

    Declaration

    Swift

    static var subclassMode: SubclassMode { get }
  • An array of protocols which should be added to the target class.

    The default value is an empty array.

    Warning

    Do not attempt to access target in the getter for this property, as that will lead to infinite recursion.

    Declaration

    Swift

    static var protocols: [Protocol] { get }
  • The current instance of the hooked class, upon which a hooked method has been called.

    Warning

    Do not attempt to implement this yourself; use the default implementation.

    Declaration

    Swift

    var target: Target { get }
  • Initializes the type with the provided target instance. Do not override this.

    Declaration

    Swift

    init(target: Target)
  • A function which is run before a target is deallocated.

    Use this to perform any cleanup before the target is deallocated.

    The default implementation is equivalent to simply returning DeinitPolicy.callOrig.

    Important

    You must not call orig.deinitializer() or supr.deinitializer() in this method. Instead, return the appropriate deinit policy.

    Declaration

    Swift

    func deinitializer() -> DeinitPolicy

    Return Value

    A DeinitPolicy representing the action to perform next.

  • orig Extension method

    A proxy to access the original instance methods of the hooked class.

    Declaration

    Swift

    public var orig: Self { get }
  • orig Extension method

    A proxy to access the original class methods of the hooked class.

    Declaration

    Swift

    public static var orig: Self.Type { get }
  • supr Extension method

    A proxy to access the hooked class’ superclass instance methods.

    Declaration

    Swift

    public var supr: Self { get }
  • supr Extension method

    A proxy to access the hooked class’ superclass class methods.

    Declaration

    Swift

    public static var supr: Self.Type { get }
  • target Extension method

    The concrete type of the hooked target (or its subclass depending on subclassMode).

    Declaration

    Swift

    public static var target: Target.Type { get }