简体   繁体   English

从它的功能中获取placemark.locality到viewDidLoad函数中(Swift)

[英]Getting placemark.locality from it's function into the viewDidLoad function (Swift)

I am a bit new in iOS app development. 我对iOS应用程序开发有些陌生。 I am currently working on a weather app that determines your location and then connects to a weather API and displays your weather conditions for the day. 我目前正在开发一个天气应用程序,该应用程序确定您的位置,然后连接到天气API,并显示当天的天气状况。 I am having a problem with getting placemark.locality out of its function so I can use it with the API to get the current weather conditions. 我无法从其功能中获取placemark.locality,因此我可以将其与API结合使用以获取当前的天气状况。

This is the function that gets the placemark.locality. 这是获取placemark.locality的函数。 Please note that it is also in my viewDidLoad function. 请注意,它也在我的viewDidLoad函数中。

func displayLocationInfo(placemark: CLPlacemark)
{
    self.locationManager.stopUpdatingLocation()
    println(placemark.locality)
    println(placemark.postalCode)
    println(placemark.administrativeArea)
    println(placemark.country)

}

If i try to call placemark.locality in any other function or class except this function it says placemark is an unresolved identifier. 如果我尝试在除此函数以外的任何其他函数或类中调用placemark.locality,则说placemark是一个无法解析的标识符。 Thanks. 谢谢。

The context of your variable is your method. 变量的上下文就是您的方法。 You can define a variable in your class (outside of your method) and stock your place mark myVariable = placemark.locality in your method. 您可以在类中(方法之外)定义变量,并在方法中存储地标myVariable = placemark.locality。

After you can use myVariable 可以使用myVariable之后

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM