类型 'AppDelegate' 不符合协议 'CLLocationManagerDelegate' - Xcode 6 中的 Swift
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26068029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Type 'AppDelegate' does not conform to protocol 'CLLocationManagerDelegate' - Swift in Xcode 6
提问by J86
I am trying to use the significant-change location service. I am using Swift with XCode on OS Mavericks. I am attempting to enhance an iOS app that I built following a tutorial.
我正在尝试使用重大更改位置服务。我在 OS Mavericks 上使用 Swift 和 XCode。我正在尝试增强我按照教程构建的 iOS 应用程序。
In my AppDelegate.swift
file I have created the following method to initialise my location manager service:
在我的AppDelegate.swift
文件中,我创建了以下方法来初始化我的位置管理器服务:
func initializeLocationManager() {
// instance of location manager class
var locationManager = CLLocationManager()
locationManager.delegate = self // error here
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}
But on the 4th line of code, I get an error saying:
但是在第 4 行代码中,我收到一条错误消息:
Type 'AppDelegate' does not conform to protocol 'CLLocationManagerDelegate'
类型“AppDelegate”不符合协议“CLLocationManagerDelegate”
Why am I getting this error? How do I fix this?
为什么我收到这个错误?我该如何解决?
回答by Tommy
The error says:
错误说:
Type 'AppDelegate' does not conform to protocol 'CLLocationManagerDelegate'
类型“AppDelegate”不符合协议“CLLocationManagerDelegate”
So:
所以:
You are getting it because your class with the name AppDelegate
does not conform to the protocol CLLocationManagerDelegate
.
你得到它是因为你的名字的类AppDelegate
不符合协议CLLocationManagerDelegate
。
You can fix this by making that class conform to that protocol. So implement the methods that are required by the protocol, then declare that your class conforms to it.
您可以通过使该类符合该协议来解决此问题。因此,实现协议所需的方法,然后声明您的类符合它。
回答by zisoft
You have to provide at least the CLLocationManager.didUpdateLocations
function in your AppDelegate class.
您必须至少CLLocationManager.didUpdateLocations
在 AppDelegate 类中提供该函数。