TweakContext

@dynamicMemberLookup
public final class TweakContext
extension TweakContext: CustomDebugStringConvertible

The context in which tweaks live.

A TweakContext object provides a facade to interact with tweaks, like showing tweaks and import tweaks.

You can create as many TweakContext objects as you like. But one context is sufficient in most cases.

  • A flag indicates whether the context is showing the tweak window.

    Declaration

    Swift

    public internal(set) var isShowing: Bool { get }
  • Creates and initializes a tweak context with the given config, delegate and the tweak lists.

    Declaration

    Swift

    public init(config: Config = .init(), delegate: TweakContextDelegate? = nil, @TweakContainerBuilder<TweakList> _ lists: () -> [TweakList])

    Parameters

    config

    The meta data of the context. The default is a default config object.

    delegate

    The object that acts as the delegate of the context. The delegate is not retained. The default is nil.

    lists

    The lists of tweaks of the context. The lists and the sections/tweaks in them are sorted by their names in alphabetic order.

  • Undocumented

    Declaration

    Swift

    public subscript<Value>(dynamicMember keyPath: KeyPath<Config, Value>) -> Value { get }
  • Shows the tweak widow of the context.

    This method will do nothing:

    1. if there is a showing window.
    2. If the context has no list at all.

    Note

    You should only call this method in main thread.

    Declaration

    Swift

    func show(locateAt tweak: AnyTweak? = nil, completion: ((Bool) -> Void)? = nil)

    Parameters

    tweak

    The tweak that should be located at when window is shown.

    completion

    A block that TweaKit calls after showing the context window.

  • Dismisses the current showing tweak window of the context.

    1. This method will do nothing if there is no showing window.
    2. You cannot dismiss the window when it is floating.

    Note

    You should only call this method in main thread.

    Declaration

    Swift

    func dismiss(completion: ((Bool) -> Void)? = nil)

    Parameters

    completion

    A block that TweaKit calls after dismissing the context window.

  • Imports tweaks for the source.

    Tweaks that not in the context will be ignored.

    Note

    You should only call this method in main thread.

    Declaration

    Swift

    func `import`(from source: TweakTradeSource, completion: ((TweakError?) -> Void)? = nil)

    Parameters

    source

    The source of the tweaks to be imported.

    completion

    A block that TweaKit calls after the source has been import.

  • Reset all the tweaks’ values and info to the default ones.

    Declaration

    Swift

    func reset()
  • Search tweaks in the current context.

    This method will use the same search strategies specified in TweakContextDelegate.

    \ You should get the same results as searching with the tweak UI. Calling this method will also contribute to search history in the tweak UI.

    Declaration

    Swift

    func search(with keyword: String) -> [[AnyTweak]]

    Parameters

    keyword

    The keyword to search. An empty keyword means searching nothing.

    Return Value

    Tweaks that match the given keyord. Tweaks from the same section are grouped together.

  • A model represents the meta data of a TweakContext object.

    See more

    Declaration

    Swift

    struct Config
  • Declaration

    Swift

    public var debugDescription: String { get }