MotionSupport

@MainActor
public struct MotionSupport

This struct provides utility methods for Motion classes.

Additive utility methods

  • Registers an Additive motion. Any custom classes that conform to the Additive 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’s operationID property.

  • Removes an Additive motion from the registered list. Any custom classes that conform to the Additive 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 other Additive 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 no Additive object is targeting this property.

Utility methods

  • 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 a PropertyData object with only an end value. In cases 1 and 2, a PropertyData object with both start and end values will be returned. In the third case, a PropertyData 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 the PropertyData‘s keyPath property.

    originalValue

    An optional value representing the current value of the target object property.

    startValue

    An optional value to be supplied to the PropertyData‘s start property.

    endValue

    A value to be supplied to the PropertyData‘s end property.

    isAdditive

    Denotes whether this PropertyData will be used with an additive Motion. If true, optimizations that prevent the PropertyData 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 a PropertyData object with only an end value. In cases 1 and 2, a PropertyData object with both start and end values will be returned. In the third case, a PropertyData 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 the PropertyData‘s keyPath 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‘s start property.

    endValue

    A value to be supplied to the PropertyData‘s end property.

    isAdditive

    Denotes whether this PropertyData will be used with an additive Motion. If true, optimizations that prevent the PropertyData from being built will not occur as it would result in incorrect additive calculations.

    Return Value

    An optional PropertyData object using the supplied values.