TweakType
public protocol TweakType
A abstract type that represents a tweak. Every tweak type has its own unique logic. For example, numeric tweak need handle minimum/maximum value but selection tweak need to handle the selection options.
TweaKit
uses different types for each tweaks under the hood.
But we don’t want to expose these types and to provide a unified API for users.
So instead of writing code like:
NumericTweak("one tweak", defaultValue: 1, from: 1, to: 100, stride: 1)
SelectionTweak("another tweak" defaultValue: 1, options: [1, 2, 3])
We can write code like:
Tweak("one tweak", defaultValue: 1, from: 1, to: 100, stride: 1)
Tweak("another tweak" defaultValue: 1, options: [1, 2, 3])
We use TweakType
to implement a class cluster that groups a number of private,
concrete tweak subclasses under a public, abstract superclass Tweak
.
-
The value type of the tweak.
Declaration
Swift
associatedtype Value
-
the concrete tweak type.
Declaration
Swift
associatedtype Base = Self
-
Creates and initializes a tweak with the given concrete type.
Declaration
Swift
init(base: Base)
Parameters
base
The concrete tweak object.
-
init(name:
Extension methoddefaultValue: from: to: stride: ) Creates and initializes a tweak for
Numbered
type.Parameters
name
The name of the tweak.
defaultValue
The default value of the tweak.
from
The maximum value of the tweaks. This value must be greater than the minimum value.
to
The minimum value of the tweak. This value must be less than the maximum value.
stride
The stride when changing value of the tweak.
-
init(name:
Extension methoddefaultValue: options: ) Creates and initializes a tweak for
Selectable
type.Parameters
name
The name of the tweak.
defaultValue
The default value of the tweak.
options
The selection options. The options must not be empty and must contain the default value.
-
init(name:
Extension methoddefaultValue: ) Creates and initializes a tweak with the given name and default value.
Declaration
Swift
init(name: String, defaultValue: Value)
Parameters
name
The name of the tweak.
defaultValue
The default value of the tweak.