期望工具和逻辑或

时间:2018-10-02 06:58:38

标签: linux expect

我对我的脚本使用MyViewController命令。我有几个不同的提示,我需要使用OR表示。

是否可以做这样的事情?

override func viewDidLoad() {
    super.viewDidLoad()

    view.addGestureRecognizer({
        let swipeRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(onSwipeLeft))
        swipeRecognizer.direction = .left
        return swipeRecognizer
    }())
}

@objc private func onSwipeLeft() {
    let controllerToBePushed = UIStoryboard(name: "my_storyboard_name", bundle: nil).instantiateViewController(withIdentifier: "the_identifier_I_set_in_storyboard") as! WhateverTheTypeOfMyViewControllerIs
    navigationController?.pushViewController(controllerToBePushed, animated: true)
}

1 个答案:

答案 0 :(得分:2)

期望已经内置了,例如:

expect {
  "Hello. Press y for YES"  {send -- "y\r"}
  "Welcome again. Press y"  {send -- "y\r"}
}

如果动作太大,则可以将其放入函数中。但是,如果您愿意,可以使用正则表达式 a | b

expect -re "Hello. Press y for YES|Welcome again. Press y"  {send "y\r"}