swift 用关键字作为方法名称

在 swift 中可以使用系统关键字来作为方法名称,只需要给关键字加上单引号即可

    private func setUI() -> Void{
        let button = UIButton(type: .custom)
        button.frame = self.view.bounds
        button.setTitle("回去", for: .normal)
        button.addTarget(self, action: #selector(`return`), for:.touchUpInside)
        self.view.addSubview(button)
    }
   // 看这个方法的名字
    @objc func `return`() -> Void{
        print("低调")
    }

你可能感兴趣的:(swift 用关键字作为方法名称)