Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 498
Khadija Daruwala Avatar asked Jun 24 '16 04:06

Khadija Daruwala


2 Answers

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.

@IBOutlet weak var mapView: MKMapView

For this you'll have to import MapKit

import MapKit
like image 51
Inn0vative1 Avatar answered Oct 21 '22 14:10

Inn0vative1


Note : Updating this answer to avoid misunderstanding as I have answered wrong earlier. Thanks @Inn0vative1 for pointing out error

For this you'll have to import MapKit

import MapKit

Your viewController did not confirm the protocol, Please conform the CLLocationManagerDelegate protocol

class MapViewController: UIViewController,CLLocationManagerDelegate {
}
like image 24
Rohit Pradhan Avatar answered Oct 21 '22 14:10

Rohit Pradhan