【问题标题】:Consecutive declarations on a line must be separated by ';' Swift [duplicate]一行中的连续声明必须用';'分隔斯威夫特 [重复]
【发布时间】:2020-11-02 02:59:09
【问题描述】:

我不断收到 - 一行上的 6 个连续声明必须用 ';' 分隔在“lpgr.minimumPressDuration = 1”之后

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    let lpgr = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress))
   
    lpgr.minimumPressDuration = 1
    lpgr.delaysTouchesBegan = true
    lpgr.delegate = self
    self.colVw.addGestureRecognizer(lpgr)

    @objc func handleLongPress(gestureReconizer: UILongPressGestureRecognizer) {
        if gestureReconizer.state != UIGestureRecognizer.State.ended {
            //When lognpress is start or running
        }
        else {
            //When lognpress is finish
        }
    }


}

【问题讨论】:

  • 如果您发布的正是您的代码,它可能是在抱怨存在于函数之外的可执行语句。
  • 我已经编辑了代码,在 jet 外部不存在任何可执行语句我仍然得到这个错误.. 我做错了什么?
  • 你错了,在函数或init之外有几行可执行语句

标签: swift


【解决方案1】:

正如@Philip Mills 指出的那样,函数之外还有可执行语句。 这是一个例子:

    lpgr.minimumPressDuration = 1
    lpgr.delaysTouchesBegan = true
    lpgr.delegate = self
    self.colVw.addGestureRecognizer(lpgr)

所有这些都是可执行语句,因为它们可以被执行。在函数中移动这些。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    • 2017-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多