Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get MapKit to work

Tags:

ios

swift

mapkit

Im following a tutorial on how to work with MapKit and I am having trouble getting past the first few steps of the tutorial. I have checked other tutorials and they all have the exact same initial steps.

  1. I place a Map Kit View onto my view controller.
  2. I add: import MapKit.
  3. I add the MapKit framework to my project.
  4. I add an outlet to my view controller.

But I get a warning that ViewController is part of module Mapkit and ignoring MapKit

And then I get an error: use of undeclared type MKMapView - which is most likely caused by MapKit not being imported.

Here's a screen shot of the errors and the code:

enter image description here

I believe I am following the tutorial steps correctly.

Any idea whats Im doing wrong?

like image 879
Bingo Avatar asked Aug 02 '26 22:08

Bingo


2 Answers

My guess here is that you called your application MapKit and you are seeing a collision with the actual MapKit framework because the modules have the same name.

Either:

  • create a new project

or

  • adjust the module name build setting (Product Build Name) to avoid a conflict.
like image 65
Seán Labastille Avatar answered Aug 04 '26 12:08

Seán Labastille


Try this, it worked for me.

import UIKit
import MapKit

class ViewController: UIViewController {

    @IBOutlet weak var map: MKMapView!
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

Apart of the weak reference and the syntax issues I would suggest you to check your Project name - the name might clashes with the iOS library! This issue happened to me in the past - check this out If it doesn't work for you let me know

like image 28
Gal Marom Avatar answered Aug 04 '26 11:08

Gal Marom