iOS Apprentice,Tutorial 3, Page 198 crash in Xcode 10

It complains that “Argument type ‘[Location]’ does not conform to expected type ‘MKAnnotation’” in “MapViewController.swift”. and Xcode auto Correction makes It as! MKAnnotation and then error is gone But When I run the app and tap on MapViewController and then app Crashes on a line

mapView.removeAnnotation(locations as ! MKAnnotation)

showing a message in Debug area that Could not cast value of type ‘Swift._EmptyArrayStorage’ (0x10b024d50) to ‘__C.MKAnnotation’ (0x10b034a00)

No idea About That why It happens.

Not sure about page 198, MyLocations is further along than that.

This line:

var locations = [Location]()

declares that locations is an array of Location, not a single instance.

So you need to use the plural versions of the map methods, which take an array as a parameter:


Oh The tiny Mistake I was doing , Solved

This topic was automatically closed after 166 days. New replies are no longer allowed.