在Swift中保存一组坐标

时间:2015-03-07 15:56:08

标签: swift core-data cllocation

我在Swift中保存一组CLLocation对象时出现问题。我不断收到错误

[Location setLongitude:]: unrecognized selector sent to instance 

我的位置课与我的旅行课有多对一的关系。保存我的旅行物品时,我会尝试保存一组坐标。 这是我的位置类,它引用了线程here上建议的类。

    @objc(Location)
class Location: NSManagedObject{
    @NSManaged var latitude: NSNumber!
    @NSManaged var longitude: NSNumber!
    @NSManaged var altitude: NSNumber!
    @NSManaged var timestamp: NSDate!
    @NSManaged var horizontalAccuracy: NSNumber
    @NSManaged var verticalAccuracy: NSNumber
    @NSManaged var speed: NSNumber
    @NSManaged var course: NSNumber
    @NSManaged var trip: Trip

    func initFromLocation(loc: CLLocation, currentTrip: Trip){
        self.latitude           = loc.coordinate.latitude
        self.longitude          = loc.coordinate.longitude
        self.altitude           = loc.altitude
        self.timestamp          = loc.timestamp

        self.horizontalAccuracy = loc.horizontalAccuracy > 0.0 ? loc.horizontalAccuracy : 0.0
        self.verticalAccuracy   = loc.verticalAccuracy > 0.0 ? loc.verticalAccuracy : 0.0
        self.speed              = loc.speed > 0.0 ? loc.speed : 0.0
        self.course             = loc.course > 0.0 ? loc.course : 0.0
        self.trip               = currentTrip
    }

    func location() -> CLLocation{
        return CLLocation(
            coordinate: CLLocationCoordinate2D(latitude: self.latitude.doubleValue, longitude: self.longitude.doubleValue),
            altitude: self.altitude.doubleValue,
            horizontalAccuracy: self.horizontalAccuracy.doubleValue,
            verticalAccuracy: self.verticalAccuracy.doubleValue,
            course: self.course.doubleValue,
            speed: self.speed.doubleValue,
            timestamp: self.timestamp
        )

    }

}

关于为什么我无法在课堂上设定经度或者周围发生了什么的任何想法?

0 个答案:

没有答案