我有严重的集成Speechkit
如果是这样的,我想创建两个分离viewControllers可能是更容易的情况 - 或者更logical-,你可以决定哪一个应该被观看基础上, #available(iOS 10.0, *)
让我们假设你将呈现基于另一个视图控制器按一个按钮就在ViewController2
(在代码片段,我把它叫做PreviousViewController
):
class PreviousViewController: UIViewController {
//...
@IBAction func presentApproriateScene(sender: AnyObject) {
if #available(iOS 10.0, *) {
// present the ViewController that heavily integrated with Speechkit
// maybe by perfroming a segue:
performSegueWithIdentifier("segue01", sender: self)
// or maybe by getting the it from the storyboard
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc1 = storyboard.instantiateViewControllerWithIdentifier("vc1")
presentViewController(vc1, animated: true, completion: nil)
} else {
// present the ViewController that does not suupport Speechkit
// maybe by perfroming a segue:
performSegueWithIdentifier("segue02", sender: self)
// or maybe by getting the it from the storyboard
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc2 = storyboard.instantiateViewControllerWithIdentifier("vc2")
presentViewController(vc2, animated: true, completion: nil)
}
}
//...
}
此外,你可以声明变量的时候使用它:
class ViewController: UIViewController {
//...
if #available(iOS 10.0, *) {
private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))!
} else {
// ...
}
//...
}
但同样,正如你提到的,如果你有Speechkit“重”的整合,我认为做两个Viewcontrollers会更合乎逻辑。
希望这有助于。
可能,您应该使用#available(iOS 10,*),如您所述。 –
@AhmadF当我在课堂上定义变量时呢?我只是没有弄清楚在那里做什么。 – owlswipe
“班级变数”的问题在哪里?我建议添加一个代码片段以保持清晰。 –