Caleb Caleb - 4 months ago 25
iOS Question

Getting initializer error on VewController

I get the error: "Class 'ViewController' has no initializer". I have narrowed down the problem to this function that is being called. Does anyone see the problem?

let locationManager1: CLLocationManager // your location manager
func addBoundry(loc: CLLocation)
{
if let loc: CLLocation! = locationManager1.location {
let center: CLLocationCoordinate2D = loc!.coordinate
let lat: CLLocationDegrees = center.latitude
let long: CLLocationDegrees = center.longitude
var points = [CLLocationCoordinate2DMake(lat,long),CLLocationCoordinate2DMake(lat,long),CLLocationCoordinate2DMake(lat,long),CLLocationCoordinate2DMake(lat,long)]
let polygon = MKPolygon(coordinates: &points, count: points.count)

mapView.addOverlay(polygon)

} else {
print("no location...")
}
}

Answer

when assign property use optional.

 let locationManager1: CLLocationManager?