I'm using Xcode 6.1.1 with Swift. The project is using core data to save Sightings
import Foundation
import CoreData
@objc(Sighting)
class Sighting: NSManagedObject {
@NSManaged var lat: Double
@NSManaged var lng: Double
@NSManaged var seen_at: NSDate
}
In an IBaction I create a new Sighting
@IBAction func addSighting(sender: AnyObject) {
let coordinate = locationManager.location.coordinate
let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let managedContext = appDelegate.managedObjectContext!
let sighting = NSEntityDescription.insertNewObjectForEntityForName("Sighting", inManagedObjectContext: managedContext) as Sighting
sighting.lat = coordinate.latitude
sighting.lng = coordinate.longitude
...
}
On the line "let sighting =" I get the error swift_dynamicCastClassUnconditional. Any ideas why?
Replacing the line with
let entityDescripition = NSEntityDescription.entityForName("Sighting", inManagedObjectContext: managedContext)
let sighting = Sighting(entity: entityDescripition!, insertIntoManagedObjectContext: managedContext)
seems to get past the issue but then it just results in the next line "sighting.lat =" giving the error EXC_BAD_ACCESS > objc_msgSend
coordinate.latitude is correctly returning a CLLocationDegrees
Any ideas on how to resolve this would be appreciated. Thanks!