widgetMigrator
A migrator that maps ClockKit complications to their WidgetKit replacements.
Declaration
optional var widgetMigrator: any CLKComplicationWidgetMigrator { get }Discussion
Implement this to provide an instance that can migrate a user’s ClockKit complications to their WidgetKit replacements. For example, update your data source so that it also conforms to the CLKComplicationWidgetMigrator protocol.
class ComplicationController: NSObject, CLKComplicationDataSource, CLKComplicationWidgetMigrator {
// ...
}Then, have its widgetMigrator property return self.
var widgetMigrator: CLKComplicationWidgetMigrator {
self
}Finally, implement the getWidgetConfiguration(from:completionHandler:) method. This method determines the best WidgetKit configuration for the given complication descriptor. The following example uses the Swift async version of the method.
func widgetConfiguration(from complicationDescriptor: CLKComplicationDescriptor) async -> CLKComplicationWidgetMigrationConfiguration? {
switch complicationDescriptor.identifier {
case caffeineDoseIdentifier:
return CLKComplicationStaticWidgetMigrationConfiguration(
kind: "Caffeine_Complications",
extensionBundleIdentifier: "com.example.apple-samplecode.Coffee-Tracker.watchkitapp.watchkitextension.CoffeeTracker-Complications")
case cupTotalIdentifier:
return CLKComplicationStaticWidgetMigrationConfiguration(
kind: "CupTotal_Complications",
extensionBundleIdentifier: "com.example.apple-samplecode.Coffee-Tracker.watchkitapp.watchkitextension.CoffeeTracker-Complications")
case cupAndCaffeineIdentifier:
return CLKComplicationStaticWidgetMigrationConfiguration(
kind: "CupAndCaffeine_Complications",
extensionBundleIdentifier: "com.example.apple-samplecode.Coffee-Tracker.watchkitapp.watchkitextension.CoffeeTracker-Complications")
default:
return nil
}
}