MigrationGuide3.0.md
January 7, 2025 ยท View on GitHub
MotionMachine 3.0 Migration Guide
MotionMachine 3.0 is a sizeable overhaul of core functionality, replacing its use of Key-Value Coding to read and write property values with modern Swift KeyPaths. Though most of the API is relatively the same, there are several breaking changes and functional differences to be aware of. This guide is provided to help in the transition to 3.0 from prior versions.
Platform Updates
- The minimum supported versions of iOS and tvOS have been increased to 16.0 in order to support KeyPaths in a generic way. If you need to support earlier versions of iOS or tvOS, please continue to use MotionMachine release
2.2.1. - macOS support has been added, supporting macOS 14.0 and up. A new
CGColorAssistantvalue assistant was also added to support usingCGColorwithMotionStateon AppKit. - Due to the adoption of a Swift 6 feature (parameter pack iteration), support for Swift 5.10 has been dropped. If you require an older version of Swift, please use MotionMachine release
2.2.1or older.
Notable Changes
PropertyData's string-basedpathinitialization parameters, which were used to supply Key-Value Coding paths (i.e. "frame.origin.x"), have been replaced withkeyPathparameters which take Swift KeyPaths (i.e.\UIView.frame.origin.x). These will effectively point to the same objects or property values as your existing string keypaths. This change also applies toMotionState. Note thatPropertyDatanow has astringPathproperty, but this is used by someValueAssistantclasses for Apple system types that cannot be otherwise handled using only Swift Keypaths and should not be set directly unless by your ownValueAssistantclasses.- Structs cannot be used as the top level of a KeyPath, though you can use them as a descendent of the top level object.
- Unlike previous versions of MotionMachine, Optionals in key paths are now supported, however you must provide a default value for them via a subscript when declaring the KeyPath, using the format
\Object.someOptional[default: <some default value>].
Motion'stargetObjectproperty is now typed as conforming toAnyObjectinstead ofNSObject, as KVC is no longer being used. In fact,NSObjectandNSValuehave been completely removed from MotionMachine.Motion'spropertiesForStatesinitializer parameter has been renamed tostatesand is no longer an array of states, but instead is a parameter pack of states. This was required to supportMotionState's new property generic which provides type safety and equality to thestartandendparameter values passed in.MotionStateobjects should be supplied to this parameter just like any variadic parameter, for instanceMotion(target: view, states: frameState, colorState, duration: 1.5). Unfortunately, supporting the Swift 6 pack iteration feature that MotionMachine needs to generatePropertyDataobjects from eachMotionStatemeans that support for Swift 5.10 had to be dropped.- Additive mode for
MotionandPhysicsMotionmust now be set via theoptionsinitialization parameter using the new optionadditive. The related propertyadditiveonMotionandPhysicsMotionhas now been renamed toisAdditiveand is read-only. - The
Moveableprotocol propertyreversingwas renamed toisReversing. - The
Moveableprotocol has had the propertiesisRepeatingandrepeatCyclesadded to it. Therepeatingproperty which already existed on motion classes has been renamed toisRepeating. The default valueREPEAT_INFINITEhas been moved from a top-level definition in the library to a static property onMoveable. PropertyStateshas been renamed toMotionState.PropertyDatais now a class instead of a struct.- The "magic" convenience string-based keypath values for
UIColorproperties (red, green, blue, hue, saturation, etc.) no longer exist due to the switch to using Swift KeyPaths instead of NSObject's KVC, as those are not actual properties onUIColor. Thus, please now use aMotionStatewhen you need to animate aUIColor. - Numeric value interpolations are now handled by the new assistant
NumericAssistant. Formerly,CGStructAssistantwas used for this purpose. This supports all types that conform to eitherBinaryFloatingPointorBinaryInteger, as well asNSNumber. - The default tempo class for all
TempoDrivenmotion classes is nowDisplayLinkTempoinstead ofCATempo. This is a new class which automatically chooses the correct tempo type depending on the system platform being used. For iOS, visionOS, and tvOS the class chosen will continue to beCATempo, but for newly-supported macOS it will beMacDisplayLinkTempo. Both classes internally use aCADisplayLinkobject for updates. - Tempo classes no longer subclass the
Tempoabstract class, which has been removed. They now conform to theTempoProvidingprotocol. TimerTempo's update interval now corresponds to the value ofmaximumFramesPerSecondfor theUIScreen/NSScreenthe app is running on, in order that motions do not lag behind the refresh rate of the display. For instance, if a screen'smaximumFramesPerSecondvalue is 120.0, the timer interval will be 1/120. Formerly it was locked to 60 cycles per second. You can still provide a custom value for this interval, as always.- The updating of property values on target objects has been moved from motion classes to relevant
ValueAssistantclasses instead. This better focusesMotionandPhysicsMotionon pure value interpolations and gives the task of object handling to theValueAssistantclasses that have the most knowledge of those objects. - The update closure type definitions for
MotionSequenceandMotionGrouphave been moved inside their classes to provide better scoping. - Some methods have been removed from the various
ValueAssistantclasses.ValueAssistant-conforming classes should now be update target object properties using the newupdate(property: newValue:)method. - Internal platform availability checks have been improved. Theoretically this may allow MotionMachine to now run on non-Apple platforms on which Swift is available, though this has not been tested.
NumericAssistantandSIMDAssistantare the only twoValueAssistantclasses which only require the Foundation framework, and thus may be usable on non-Apple Swift platforms out of the box.