如何将segue存储为变量并仍然使用它?

时间:2018-01-31 02:08:25

标签: swift

var realAddress1 : CLLocationDegrees = 0.0
var realAddress2 : CLLocationDegrees = 0.0
var cooksLocation = CooksLocation()
let hello : [String] = []

func prepare(for segue: UIStoryboardSegue, sender: Any?) -> CLLocationDegrees  {
    let cooksLocation = segue.destination as! CooksLocation
    cooksLocation.address1 = realAddress1

    return realAddress1
}

以下是我的代码示例。问题是它不会返回var realAdress1的新值。

1 个答案:

答案 0 :(得分:1)

问题在于

func prepare(for segue: UIStoryboardSegue, sender: Any?) -> CLLocationDegrees  {

不是自动调用的方法的签名。正确的签名是

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

不返回值。如果要存储值以响应被调用的方法,请将其存储在实例属性中,或调用某个方法并传递它。