UISceneActivationConditions and UIApplicationShortcutItem

Just watched the Targeting Content with Multiple Windows video. My app uses UIApplicationShortcutItem and UIApplication.shortcutItems.


So I thought it would be useful to set the targetContentIdentifier property of each shortcut item so when the user selects one of the shortcuts, they can be brought to the mose appropriate scene in the app.


But UIApplicationShortcurItem targetContentIdentifer is a read-only property. Is this is mistake?


The documentation for UISceneActiviationConditions states (emphesis mine):


Many different objects contain a

targetContentIdentifier
property, including
NSUserActivity
,
UNNotificationContent
, and
UIApplicationShortcutItem
. When creating those objects, fill that property with a value that uniquely describes the event and matches your scenes' predicates.


Kind of hard to do when the property is read-only.


Am I missing something or is this an API bug?

Replies

UIApplicationShortcutItem works like NSArray in that they both immutable but provide mutable subclasses (ie UIMutableApplicationShortcutItem and NSMutableArray). Therefore if you want to set the targetContentIdentifier for a shortcut item you have to do something like the following:

let shortcutItem = UIMutableApplicationShortcutItem(type: "com.myapp.shortcut", localizedTitle: "Shortcut")
shortcutItem.targetContentIdentifier = "myapp://shortcut"
UIApplication.shared.shortcutItems = [shortcutItem]