I having an issues on saving a set of CLLocation
s object in Swift. I keep getting an errors of
[Location setLongitude:]: unrecognized selector sent to instance
My Location class had many-to-one relationship with my trip class. I try to save a set of coordinates when saving my trip object as well. Here is my Location Class, which refer on the class suggested on a thread 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
)
}
}
Any ideas on why I unable to set the longitude in my class or what going on around?