0

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...")
        }
    }
1

2 Answers 2

1

when assign property use optional.

 let locationManager1: CLLocationManager?
Sign up to request clarification or add additional context in comments.

Comments

1

When you say let locationManager1: CLLocationManager, you're declaring a property that must not be nil, but not actually assigning anything to it.

So, you either need to declare an init that ensures locationManager1 is assigned exactly one value (it's a let constant, not a var, after all!) or initialize the property inline like:

let locationManager1 = CLLocationManager()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.