ios - 如何检查快捷方式是否已经存在?
问题描述
我已经编写了这个方法来检查给定 id 的快捷方式是否已经存在。
public static func shortcutExists(id: String, completion: @escaping ((Bool) -> Void)) {
var exists = false
INVoiceShortcutCenter.shared.getAllVoiceShortcuts { voiceShortcutsFromCenter, error in
if let voiceShortcutsFromCenter = voiceShortcutsFromCenter {
for voice in voiceShortcutsFromCenter {
if id == voice.shortcut.intent?.identifier { // What to do here?
exists = true
break
}
}
} else {
...
}
completion(exists)
}
}
我为每个意图条目都有一个唯一的 ID。但我不知道如何将该 ID 保存为意图的标识符。标识符似乎相当只读,并且似乎是自动生成的。
请问我怎样才能做到这一点?
解决方案
我如何实现这一点是在每个自定义意图中添加一个独特的属性。然后在之后检查意图的属性getAllVoiceShortcuts{}
。
func checkExist(existShortcuts: [INVoiceShortcut]) -> Bool {
existShortcuts.first(where: {
let intent = $0.shortcut.intent
return intent?.customPropertyId == self.customId
}) != nil
}
推荐阅读
- haskell - 违反结合律的不正确单子的例子是什么?
- sql - SQL Server:从 col1 中删除零并与 col2 连接到新视图中
- python - keras和python中特定层的标量量化
- javascript - 带有文本字段和文件的 POST 请求
- flutter - Flutter Web 崩溃,无法打开文件 client.js
- or-tools - 不考虑完成的提货交付或工具的数量,实现利润最大化
- react-native - React 本机模拟器无法在 windows10 中启动
- segment-tree - 延迟传播范围更新
- c - 假设 NULL 常量为零是否安全?
- php - Mysql - Docker:连接问题