gpt4 book ai didi

ios - swift 全局变量字符串返回 nil

转载 作者:行者123 更新时间:2023-11-28 07:59:06 33 4
gpt4 key购买 nike

在 Swift 4 中无法调用存储在全局变量中的值这是代码看起来像

var coord : String!

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

let locValue: CLLocationCoordinate2D = (manager.location?.coordinate)!
print("Locations : \(locValue.latitude), \(locValue.longitude)")

let lat: String = String(format:"%f", locValue.latitude)
let lon: String = String(format:"%f", locValue.longitude)
let node = lat + "," + lon
self.coord = node
print("Coordinate", node)
}

然后我尝试在另一个函数中调用它,

func getAddress(){
let location = coord
}

但它返回为 nil谁能告诉我我在这里错过了什么

最佳答案

你必须为坐标变量分配内存。喜欢,

变量坐标 = 字符串()

关于ios - swift 全局变量字符串返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47171798/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com