从 Void 函数中提取字符串变量

Extract a String Variable from a Void function

这是我的问题:

我想从 Launch App() 函数中恢复变量 jan 并将其插入上面的覆盖中而不是 "Hello there"。

        override func prepare(for segue: UIStoryboardSegue, sender: Any?){

            let destVC : troisViewController = segue.destination as! troisViewController

            destVC.dataFromFirst = "Hello there"
        }

        func launchApp(decodedURL: String) -> Void {

            if presentedViewController != nil{
            return
            }

        let jan: String = "\(decodedURL)"
        print(jan)


        self.performSegue(withIdentifier: "troissegue", sender: self)
    }

问题是解码出来的URL是用我phone的摄像头得到的条码,解决方法类型:destVC.dataFromFirst = launchApp()不行...

有没有人有类似的问题?

提前致谢

一个简单的解决方案是将字符串作为 sender 参数传递

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {    
    if segue.identifier == "troissegue" {
        let destVC = segue.destination as! troisViewController
        destVC.dataFromFirst = sender as! String
    }
}

func launchApp(decodedURL: String) -> Void {

    if presentedViewController != nil { return }
    self.performSegue(withIdentifier: "troissegue", sender: decodedURL)
}