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

时间:2020-02-24 11:26:14

标签: swift avfoundation void

这是我的问题:

我想从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是使用手机的摄像头获取的条形码,类型为destVC.dataFromFirst = launchApp()的解决方案不起作用...

有人有类似的问题吗?

提前谢谢

1 个答案:

答案 0 :(得分:3)

一个简单的解决方案是将字符串作为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)
}