Dan*_*nyl 3 ios nsorderedset swift sirikit
I want to use this function's prototype for adding vocabulary to SiriKit. Apple's documentation shows the following sample code:
let workoutNames = self.sortedWorkoutNames()
let vocabulary = INVocabulary.shared()
vocabulary.setVocabularyStrings(workoutNames, of: .workoutActivityName)
Run Code Online (Sandbox Code Playgroud)
According to the documentation, I need to use an NSOrderedSet type for self.sortedWorkoutNames().
How to declare it and set it with an array of Strings?
EDIT: About the context project, I'm using Intents with Siri. The goal here, is to use specific word like 'Benchpress' or 'Chicken' just to start my workout app with an INStartWorkoutIntent already implemented and working like a charm.
如果您查看 Apple 的 SiriKit 示例代码,您可以发现他们的函数sortedWorkoutNames()返回一个NSOrderedSet. workoutNames查看Objective-C版本中的类型:
NSOrderedSet* workoutNames = [self sortedWorkoutNames];
Run Code Online (Sandbox Code Playgroud)
在 Swift 中那就是
let workoutNames: NSOrderedSet = self.sortedWorkoutNames()
Run Code Online (Sandbox Code Playgroud)
如果您想要传递一个数组INVocabulary.setVocabularyStrings(_:of:),则需要将其转换为有序集。正如 @larme 在他的评论中所说, NSOrderedSet 有一个将数组作为输入的初始值设定项。
您的代码可能如下所示:
let myVocab = ["Benchpress", "Squats", "Deadlift"]
let myVocabSet = NSOrderedSet(array: myVocab) //Convert myVocab to an NSOrderedSet
let vocabulary = INVocabulary.shared()
vocabulary.setVocabularyStrings(myVocabSet, of: .workoutActivityName)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7597 次 |
| 最近记录: |