Search code examples
iosswiftmkmapviewsfsafariviewcontroller

MKMapView error and SFViewController error


I get an error whenever I try to use a mapview

"Use of undeclared type of MKMapView"

and "Use of undeclared type MKMapViewDelegate."

I also get the error when trying to call an SFSafariViewController.

For the first two, the code is

class pinViewController: UIViewController, UITextFieldDelegate, MKMapViewDelegate {

    @IBOutlet weak var locationTextField: UITextField!
    @IBOutlet weak var addPinBtn: UIButton!
    @IBOutlet weak var linkTextField: UITextField!
    @IBOutlet weak var mapView: MKMapView!

The safari view controller the code is

@IBAction func signUp(_ sender: AnyObject) {

        let url = NSURL(string:"https://www.udacity.com/account/auth#!/signup")
        let safariVC = SFSafariViewController(url: url as! URL)
        present(safariVC, animated: true, completion: nil)

Solution

  • You need to import MapKit framework to access Apple Map related class and Safari​Services framework to access SFSafariViewController. So simply add two import statement in your pinViewController

    import MapKit
    import Safari​Services
    

    Remember one ting that batter if class name start with Capital latter, so simply change pinViewController to PinViewController