The weak can only be applied to class types and classes that are not <<errortype>>

I try to add a map using GMSMapView , but I get errors when I create an output for the view.

The following is a snippet of code:

 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 get the following errors in line

 @IBOutlet weak var mapVIew: GMSMapView!: 
  • weak can only be applied to class and class protocol types, not <>
  • use of undeclared type "GMSMapView"

Please someone can help me.

+6
source share
4 answers

Note. Updating this answer to avoid misunderstanding, as I answered incorrectly before. Thanks @ Inn0vative1 for pointing out the error

To do this, you will need to import MapKit

 import MapKit 

Your viewController has not confirmed the protocol; compatible with the CLLocationManagerDelegate protocol

 class MapViewController: UIViewController,CLLocationManagerDelegate { } 
+1
source

The marked answer is the wrong answer to this problem. In case someone else does this, the problem is that the required structure is not imported. In this case, GoogleMaps. To fix this, add at the top of the file

 import GoogleMaps 

Another example is getting an error after adding MkMapView.

 @IBOutlet weak var mapView: MKMapView 

To do this, you will need to import MapKit

 import MapKit 
+8
source

This problem will also occur if the library containing the control is not imported.

for example, if we try to create an IBOutlet for a PDFView control and the Quartz library is not imported, this error appears.

0
source

Recently, I also met this issue. I set this by --xxxTests target membership --xxxTests . One of my files checked the target of xxxTests .

0
source

All Articles