I am trying to learn Xcode using iOS 14 Programming for Beginners (Packt Pub). I have had several problems with the code so I have been ultra careful and I can't find any mistakes. There is also another error in the code in an extension in the code. Here is a copy of the code:
/
// MapViewController.swift
// EatOut
//
// Created by Tony Hudson on 15/07/2021.
// Links to: Item -308,318,319,320,321,324,341,352,353
import UIKit
import MapKit
class MapViewController: UIViewController,MKMapViewDelegate {
@IBOutlet weak var mapView: MKMapView!
let manager = MapDataManager()
var selectedRestaurant: RestaurantItem?
override func viewDidLoad() {
super.viewDidLoad()
initialize()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?){
switch segue.indentifier! { //<<Value of type 'UIStoryboardSegue' has no member 'indentifier'
case Segue.showDetail.rawValue: showRestaurantDetail(segue: segue)
default:
print("Segue not added")
}
}
}
// MARK: Private Extension
private extension MapViewController {
func initialize() {
mapView.delegate = self
manager.fetch {(annotations) in addMap(annotations)}
}
func addMap(_ annotations: [RestaurantItem]) {
mapView.setRegion(manager.currentRegion(latDelta: 0.5, longDelta: 0.5), animated: true)
mapView.addAnnotations(manager.annotations)
}
func showRestaurantDetail (segue: UIStoryboardSegue){
if let viewController = segue.destination as? RestaurantDetailViewController, let restaurant = selectedRestaurant {
viewController.selectedRestaurant = restaurant
}
}
}
// MARK: MKMapViewDelegate
extension MapViewController: MKMapViewDelegate { //<< Redundant conformance of 'MapViewController' to protocol 'MKMapViewDelegate'
func mapView(_ mapView: MKMapView, annotationView view:MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
guard let annotation = mapView.selectedAnnotations.first
else{
return
}
selectedRestaurant = annotation as? RestaurantItem
self.performSegue(withIdentifier: Segue.showDetail.rawValue, sender: self)
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation ) -> MKAnnotationView? {
let identifier = "custompin"
guard !annotation.isKind(of: MKUserLocation.self) else {
return nil
}
var annotationView: MKAnnotationView?
if let customAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) {
annotationView = customAnnotationView
annotationView?.annotation = annotation
} else {
let av = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
av.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
annotationView = av
}
if let annotationView = annotationView {
annotationView.canShowCallout = true
annotationView.image = UIImage(named: "custom-annotation")
}
return annotationView
}
}
I am wondering if there is some action that I have not done previously that is causing these errors. Can anyone help?