Groups

  • A marker type which allows grouping and deferring the initialization of hooks.

    Declaring a Group

    In order to create a group, simply declare a type (usually a struct) which conforms to HookGroup.

    Hooks are assigned to groups by setting the AnyHook.Group associatedtype to the desired group (usually using a typealias; see the example below). Every hook belongs to exactly one group. By default, all hooks are part of DefaultGroup.

    Activating a Group

    When a group is activated, it refers to the enabling of all of the hooks in that group. A group can be activated at most once.

    The group DefaultGroup is automatically activated during Orion’s initialization sequence. Custom groups, on the other hand, are not activated automatically. You may choose to activate a custom group whatever you like (but at most once), or choose to not activate it at all.

    In order to activate a group, create a new instance of the group’s type, and call activate() on it. Orion will then enable all of the hooks assigned to that group. The instance on which you called activate() will be saved by Orion and will become accessible to the group’s hooks via the AnyHook.group accessor. This means that you can add properties to your group’s type which can effectively be used as “arguments” that are passed during activation.

    Example

    The following is a snippet of a tweak which activates NewStuff on iOS 14 or higher, and OldStuff on older iOS versions. In the former case, a boolean argument is passed to indicate whether the device has a notch. The class names used in this tweak are for demonstrative purposes only; there’s no guarantee that classes with these names actually exist.

    struct iOS14Stuff: HookGroup {
        let hasNotch: Bool
    }
    
    struct iOS13Stuff: HookGroup {}
    
    class CallBarHook: ClassHook<UIView> {
        typealias Group = iOS14Stuff
        static let targetName = "SBCallBarView"
        // ...
    }
    
    class AppLibraryHook: ClassHook<UIView> {
        typealias Group = iOS14Stuff
        static let targetName =
            group.hasNotch ? "SBModernAppLibraryView" : "SBAppLibraryView"
        // ...
    }
    
    class CallScreenHook: ClassHook<UIView> {
        typealias Group = iOS13Stuff
        static let targetName = "SBCallScreenView"
        // ...
    }
    
    struct MyTweak: Tweak {
        init() {
            if #available(iOS 14, *) {
                let hasNotch = // ...
                iOS14Stuff(hasNotch: hasNotch).activate()
            } else {
                iOS13Stuff().activate()
            }
        }
    }
    
    See more

    Declaration

    Swift

    public protocol HookGroup
  • The default group which hooks are assigned to. Hooks which belong to this group are automatically activated during Orion’s standard initialization process.

    Orion activates this group after calling Tweak.init() but prior to calling Tweak.tweakDidActivate().

    See

    HookGroup

    Declaration

    Swift

    public struct DefaultGroup : HookGroup