Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created September 29, 2018 19:21
Show Gist options
  • Save vialyx/f96ebd6382021aafc5459234e8e2b147 to your computer and use it in GitHub Desktop.
Save vialyx/f96ebd6382021aafc5459234e8e2b147 to your computer and use it in GitHub Desktop.
enum Shortcuts: String {
case refreshList = "com.vialyx.MVD.refresh_list"
var identifier: String {
return rawValue
}
var title: String {
switch self {
case .refreshList:
return "shortcuts.refresh_list".localized()
}
}
var notification: Notification.Name {
switch self {
case .refreshList:
return Notification.Name(identifier)
}
}
}
extension NSUserActivity {
static func with(_ shortcut: Shortcuts) -> NSUserActivity {
let activity = NSUserActivity(activityType: shortcut.rawValue)
activity.title = shortcut.title
activity.userInfo = ["speech" : shortcut.title]
activity.isEligibleForSearch = true
if #available(iOS 12.0, *) {
activity.isEligibleForPrediction = true
activity.persistentIdentifier = shortcut.identifier
} else {
// Fallback on earlier versions
}
return activity
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment