PersianBlue PersianBlue - 5 months ago 146
Swift Question

weak may only be applied to class and class-bound protocol types not <<errortype>>

I'm trying to add a map using

GMSMapView
but I'm getting errors when I create an outlet for the view.

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!:



  1. weak may only be applied to class and class-bound protocol types not <>

  2. use of undeclared type "GMSMapView"



Please can someone help me out

Answer

Your viewController did not cofirms the protocol,hence compiler will give you error. Please confirm the CLLocationManagerDelegate protocol

class MapViewController: UIViewController,CLLocationManagerDelegate {
}