Reputation: 1153
I am trying to convert a cllocationcoordinate2d into a cllocation. I get the error "Expected expression in container literal" on line 12 of the code below. I also get the error "Cannot convert value of type cllocationcoordinate2d into expected value cllocation" on line 13 but that is because line 12 isn't working correctly.
@IBAction func makeEvent(sender: UIButton)
{
let center = CLLocationCoordinate2D(latitude: loc1.coordinate.latitude, longitude: loc1.coordinate.longitude)
let lat: CLLocationDegrees = center.latitude
let long: CLLocationDegrees = center.longitude
self.pointAnnotation1 = MKPointAnnotation()
self.pointAnnotation1.title = "Event"
self.pointAnnotation1.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: long)
self.pinAnnotationView = MKPinAnnotationView(annotation: self.pointAnnotation1, reuseIdentifier: nil)
self.mapView?.centerCoordinate = self.pointAnnotation1.coordinate
self.mapView.addAnnotation(self.pinAnnotationView.annotation!)
CLLocation *center = [[CLLocation alloc] initWithLatitude:latt longitude:longg]
eventRecord.setObject(center, forKey: "event")
let publicData = CKContainer.defaultContainer().publicCloudDatabase
publicData.saveRecord(eventRecord) { record, error in
}
if error == nil
{
print("Location saved")
}
loadEvent(){ (error, records) in
if error != nil {
print("error fetching locations")
} else {
print("Found Event")
}
}
}
Upvotes: 1
Views: 5665
Reputation: 782
You are mixing up Objective-C and Swift.
Try this:
let center = CLLocation(latitude: lat, longitude: long)
Instead of:
CLLocation *center = [[CLLocation alloc] initWithLatitude:latt longitude:longg]
Upvotes: 6