Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active August 30, 2020 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/8cb68e4ed8abba67d9d33018d5cd4f6b to your computer and use it in GitHub Desktop.
Save laevandus/8cb68e4ed8abba67d9d33018d5cd4f6b to your computer and use it in GitHub Desktop.
func reloadShortcuts() {
let context = dependencyContainer.persistentContainer.viewContext
let plants = Plant.all(in: context).sorted(by: { $0.name < $1.name })
let items = plants.map({ (plant) -> UIApplicationShortcutItem in
return UIApplicationShortcutItem(type: UIApplicationShortcutItem.Action.showPlant.rawValue,
localizedTitle: plant.name,
localizedSubtitle: nil,
icon: UIApplicationShortcutIcon(systemImageName: "leaf.arrow.circlepath"),
userInfo: ["id": plant.id] as [String: NSSecureCoding])
})
UIApplication.shared.shortcutItems = items
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment