Confused about an error
I'm getting an error using the following code:
let context: NSManagedObjectContext = self.getPrivateContext()
context.performBlockAndWait {
if let key = self.appDelegate.APIKey {
apiKey = key
} else {
if let key: String = self.appDelegate.MainCoreDataService.getApiKeyFromDatabase(context) where key != "" {
apiKey = key
self.appDelegate.APIKey = key
}
}
}
internal func getApiKeyFromDatabase(context: NSManagedObjectContext) -> String? {
let fetchRequest: NSFetchRequest = NSFetchRequest()
if let entity: NSEntityDescription = NSEntityDescription.entityForName(Constants.CoreData.Device.NameOfTable, inManagedObjectContext: context) {
// Edit the entity name as appropriate.
fetchRequest.entity = entity
do {
guard let devices: [Device] = try context.executeFetchRequest(fetchRequest) as? [Device]
where devices.count == 1
else {
Constants.Log.error("Apikey not found in database (unexpected result!)")
return nil
}
let key = devices[0].apiKey
return key
} catch {
Constants.Log.error("Apikey not found in database (unexpected result!)")
}
}
return nil
}
I'm quite lost. It's telling me about the release of an object not being correct. I'm lost. Do you maybe know what i could do to fix this? I'm using Swift.
Invalid concurrent access to managed object calling 'release'; Stacktrace: (
0 x App 0x00549a71 ValidateConcurrency + 228
1 x App 0x005497b7 CustomSubclassRelease + 18
2 x App 0x00265ad4 TFC8x_App6DevicecfMS0_FT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0 + 264
3 x App 0x00265bc8 TToFC8x_App6DevicecfMS0_FT6entityCSo19NSEntityDescription30insertIntoManagedObjectContextGSqCSo22NSManagedObjectContext__S0 + 100
4 CoreData 0x220bbf2b
I can't figure out what code lines frames 2 and 3 refer to. I'd recommend putting a breakpoint in ValidateConcurrency for when it fails to try to figure out exactly which lines this stacktrace corresponds to.