xcode 弱可能只适用于类和类绑定的协议类型而不是 <<errortype>>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38005594/
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
weak may only be applied to class and class-bound protocol types not <<errortype>>
提问by PersianBlue
I'm trying to add a map using GMSMapView
but I'm getting errors when I create an outlet for the view.
我正在尝试添加地图,GMSMapView
但在为视图创建插座时出现错误。
The following is the code snippet:
以下是代码片段:
import UIKit
import GoogleMaps
class MapViewController: UIViewController {
@IBOutlet weak var mapVIew: GMSMapView!
@IBOutlet weak var mapCenterPinImage: UIImageView!
@IBOutlet weak var pinImageVerticalConstraint: NSLayoutConstraint!
var searchedTypes = ["bakery", "bar", "cafe", "grocery_or_supermarket", "restaurant"]
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "Types Segue" {
let navigationController = segue.destinationViewController as! UINavigationController
let controller = navigationController.topViewController as! TypesTableViewController
controller.selectedTypes = searchedTypes
controller.delegate = self
}
}
}
I'm getting the following errors at line
我在行中收到以下错误
@IBOutlet weak var mapVIew: GMSMapView!:
- weak may only be applied to class and class-bound protocol types not <>
- use of undeclared type "GMSMapView"
- 弱可能只适用于类和类绑定的协议类型而不是 <>
- 使用未声明的类型“GMSMapView”
Please can someone help me out
请有人帮我
采纳答案by Rohit Pradhan
Note : Updating this answer to avoid misunderstanding as I have answered wrong earlier. Thanks @Inn0vative1 for pointing out error
注意:更新此答案以避免误解,因为我之前回答错误。感谢@Inn0vative1 指出错误
For this you'll have to import MapKit
为此,您必须导入 MapKit
import MapKit
Your viewController did not confirm the protocol, Please conform the CLLocationManagerDelegate
protocol
您的 viewController 没有确认协议,请遵守CLLocationManagerDelegate
协议
class MapViewController: UIViewController,CLLocationManagerDelegate {
}
回答by Inn0vative1
The marked answer is not the correct answer to this problem. In case anyone else hits this, the problem is the framework needed is not imported. In this case GoogleMaps. The fix for this is, at the top of file add
标记的答案不是这个问题的正确答案。如果其他人遇到此问题,问题是所需的框架未导入。在这种情况下,谷歌地图。对此的修复是,在文件顶部添加
import GoogleMaps
Another example is if you get the error after adding an MkMapView.
另一个例子是如果您在添加 MkMapView 后收到错误。
@IBOutlet weak var mapView: MKMapView
For this you'll have to import MapKit
为此,您必须导入 MapKit
import MapKit
回答by Rohit Pradhan
One will also get this issue, if the library containing the control is not imported.
如果未导入包含控件的库,也会出现此问题。
eg., if we are trying to create an IBOutlet to a PDFView control and Quartz library is not imported, this error pops in.
例如,如果我们尝试为 PDFView 控件创建 IBOutlet 并且未导入 Quartz 库,则会弹出此错误。
回答by Monkey Coding
Recently I also met this problem. I fixed this by uncheck the target membership --xxxTests
. One of my file checked the xxxTests
target.
最近我也遇到了这个问题。我通过取消选中目标成员资格来解决这个问题--xxxTests
。我的一个文件检查了xxxTests
目标。