我正在将我的应用程序更新为Swift 2.0,但是我遇到了CLLocationManager
问题。无法访问不同类别的变量
我已经使用了这段代码了一段时间,所以我有些困惑,为什么它突然成为2.0中的一个问题。我使用一个全局变量(懒惰,我知道),但它似乎并没有在比它在声明的一个以外的任何其它类访问我收到此错误:
Use of unresolved identifier 'locationManager'
这是代码我在课堂,我声明了locationManager
:
var locationManager = CLLocationManager()
class InitalViewController: UITableViewController, UISearchBarDelegate, UISearchDisplayDelegate {
if #available(iOS 8.0, *) {
locationManager.requestAlwaysAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
if CLLocationManager.locationServicesEnabled() {
//Requests location use from user for maps
locationManager.requestWhenInUseAuthorization()
}
}
}
而且这是在其他类代码:
@IBAction func centerOnLocation(sender: AnyObject) {
if locationManager.location != nil {
let locationCamera = MKMapCamera()
locationCamera.heading = parkPassed.orientation!
locationCamera.altitude = 600
locationCamera.centerCoordinate.latitude = locationManager.location.coordinate.latitude
locationCamera.centerCoordinate.longitude = locationManager.location.coordinate.longitude
mapView.setCamera(locationCamera, animated: true)
}
}
人有什么想法?
,但我仍然得到同样的错误很遗憾。 – user3746428