Swift - Google Map crashes with 'unexpectedly found nil' error
<p>I am trying to set a <code>GoogleMap</code> to a <code>UIView</code> and add it as a Subview. However, when running the app I get this error:</p>

<blockquote>
  <p>fatal error: unexpectedly found nil while unwrapping an Optional value</p>
</blockquote>

<p>It crashes at code line:</p>

<pre><code>mapView.camera = camera
</code></pre>

<p><strong>Here's my full ViewController code:</strong></p>

<pre><code>class LocationViewController: UIViewController {
    @IBOutlet weak var mapView: GMSMapView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let camera = GMSCameraPosition.camera(withLatitude: 15.4989, longitude: 73.8278, zoom: 6)
        mapView.camera = camera
        mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
        mapView.isMyLocationEnabled = true
        mapView.settings.myLocationButton = true
        self.view.addSubview(self.mapView)
    }
}
</code></pre>

<p>I went through a few other similar SO threads and all of them have the same code. In my case the UI freezes and crashes with this error. What am I doing wrong?</p>

<p><strong>EDIT</strong></p>

<p>Yes, I have set the UIView's custom class as <code>GMSMapView</code></p>