เกิดข้อผิดพลาดในการแปลง CLLocationCoordinate2D เป็น CLLocation ใน Swift

ฉันกำลังพยายามแปลง cllocationcoordinate2d เป็น clolocation ฉันได้รับข้อผิดพลาด "นิพจน์ที่คาดหวังในคอนเทนเนอร์ลิเทอรัล" ในบรรทัดที่ 12 ของโค้ดด้านล่าง ฉันยังได้รับข้อผิดพลาด "ไม่สามารถแปลงค่าประเภท cllocationcoordinate2d เป็นค่าที่คาดหวัง clolocation" ในบรรทัด 13 แต่นั่นเป็นเพราะบรรทัด 12 ทำงานไม่ถูกต้อง

@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")
            }
        }
    }

person Steve    schedule 31.08.2016    source แหล่งที่มา
comment
CLLocation *center = [[CLLocation alloc] initWithLatitude:latt longitude:longg] คือ Objective-C ไม่ใช่ Swift   -  person Martin R    schedule 31.08.2016


คำตอบ (1)


คุณกำลังผสมวัตถุประสงค์ c และความรวดเร็ว ลองสิ่งนี้:

    let center = CLLocation(latitude: lat, longitude: long)

แทน:

    CLLocation *center = [[CLLocation alloc] initWithLatitude:latt longitude:longg]
person firstinq    schedule 31.08.2016