MotionSupport
@MainActor
public struct MotionSupport
This struct provides utility methods for Motion classes.
-
Registers an
Additive
motion. Any custom classes that conform to theAdditive
protocol should register their motion object.Declaration
Swift
@MainActor public static func register(additiveMotion motion: any Additive) -> UInt
Parameters
additiveMotion
The
Additive
object to register.Return Value
An operation ID that should be assigned to the
Additive
object’soperationID
property. -
Removes an
Additive
motion from the registered list. Any custom classes that conform to theAdditive
protocol should call this method when it has completed its motion.Declaration
Swift
@MainActor public static func unregister(additiveMotion motion: any Additive)
Parameters
additiveMotion
The
Additive
object to remove. -
Returns the ending value of the most recently started
Additive
motion operation for the specified object and keyPath. In order to participate in additive motion with otherAdditive
objects, custom objects should use this method to set a starting value.Example Usage
if let lastTargetValue = MotionSupport.targetValue(forObject: targetObject, targetProperty: property, requestingID: self.operationID) { properties[index].start = lastTargetValue }
Declaration
Swift
@MainActor public static func targetValue<TargetType>(forObject object: TargetType, targetProperty: PropertyData<TargetType>, requestingID: UInt) -> Double? where TargetType : AnyObject
Parameters
forObject
The object whose property value should be queried.
keyPath
The keypath of the target property, relative to the object.
Return Value
The ending value. Returns
nil
if noAdditive
object is targeting this property.
-
Builds and returns a
PropertyData
object using the supplied values.A
PropertyData
object will be created if the values you supply pass one of the following tests: 1) there’s a specified start value and that value is different than either the original value or the ending value, or 2) there’s just an original value and that value is different than the ending value, or 3) there’s no start value passed in, which will return aPropertyData
object with only an end value. In cases 1 and 2, aPropertyData
object with both start and end values will be returned. In the third case, aPropertyData
object that only has an ending value will be returned. If all those tests fail, no object will be returned.Declaration
Swift
@MainActor public static func buildPropertyData<TargetType, PropertyType>(keyPath: KeyPath<TargetType, PropertyType>, originalValue: PropertyType? = nil, startValue: PropertyType?, endValue: PropertyType, isAdditive: Bool = false) -> PropertyData<TargetType>? where PropertyType : BinaryFloatingPoint
Parameters
keyPath
A base
KeyPath
to be used for thePropertyData
‘skeyPath
property.originalValue
An optional value representing the current value of the target object property.
startValue
An optional value to be supplied to the
PropertyData
‘sstart
property.endValue
A value to be supplied to the
PropertyData
‘send
property.isAdditive
Denotes whether this
PropertyData
will be used with an additive Motion. Iftrue
, optimizations that prevent thePropertyData
from being built will not occur as it would result in incorrect additive calculations.Return Value
An optional
PropertyData
object using the supplied values. -
Builds and returns a
PropertyData
object using the supplied values.A
PropertyData
object will be created if the values you supply pass one of the following tests: 1) there’s a specified start value and that value is different than either the original value or the ending value, or 2) there’s just an original value and that value is different than the ending value, or 3) there’s no start value passed in, which will return aPropertyData
object with only an end value. In cases 1 and 2, aPropertyData
object with both start and end values will be returned. In the third case, aPropertyData
object that only has an ending value will be returned. If all those tests fail, no object will be returned.Declaration
Swift
@MainActor public static func buildPropertyData<TargetType, PropertyType, ParentType>(keyPath: KeyPath<TargetType, PropertyType>, parentPath: KeyPath<TargetType, ParentType>? = nil, originalValue: PropertyType? = nil, startValue: PropertyType?, endValue: PropertyType, isAdditive: Bool = false) -> PropertyData<TargetType>? where PropertyType : BinaryFloatingPoint
Parameters
keyPath
A base
KeyPath
to be used for thePropertyData
‘skeyPath
property.parentPath
A
KeyPath
referencing the parent object to the value being updated.originalValue
An optional value representing the current value of the target object property.
startValue
An optional value to be supplied to the
PropertyData
‘sstart
property.endValue
A value to be supplied to the
PropertyData
‘send
property.isAdditive
Denotes whether this
PropertyData
will be used with an additive Motion. Iftrue
, optimizations that prevent thePropertyData
from being built will not occur as it would result in incorrect additive calculations.Return Value
An optional
PropertyData
object using the supplied values.