Jonas
Jonas

Reputation: 2249

Rare Error while reading CoreData: data:<fault> in the CoreData Result

From time to time a rarely error occurs in my project (like every 100th Request). The request of some of my CoreData has data:<fault> and i can't use that data. I don't really understand why this happens and how to prevent this behavior.

Wrong data output example:

<NSManagedObject: 0x147ea09b0> (entity: ToDo; id: 0xd000000002f40000 <x-coredata://7B4FEA6E-1B36-467E-BE14-53CC2EE8CE21/ToDo/p190> ; data: <fault>)

Normal output is something like:

<NSManagedObject: 0x147ea0790> (entity: ToDo; id: 0xd000000002f40000 <x-coredata://7B4FEA6E-1B36-467E-BE14-53CC2EE8CE21/ToDo/p189> ; data: {
    created = "2016-02-19 15:04:42 +0000";
    text = "Some Text";
})

I get the data with:

 let fetchRequest = NSFetchRequest(entityName: "Example")

 var examples:[NSManagedObject]

 do {
            let results =
            try self.managedContext.executeFetchRequest(fetchRequest)
            examples = results as! [NSManagedObject]
 } catch let error as NSError {
            print("Could not fetch \(error), \(error.userInfo)")
 }

The problem is in the examples from the results. The code doesn't jump in the catch statement. The examples have the same length as the expected data. In my next request all data are still there. Nothing was lost. The only problem is that this data is empty for this only request.

My problem is in Swift. But i guess Objective C could have the same problem.

Anything helps. Thank you in Advance!

Upvotes: 1

Views: 1584

Answers (2)

Jonas
Jonas

Reputation: 2249

If anyone is reading this, i solved my problem, or better i know what i did wrong.

The problem was that i called to many coredata requests in a very short time. It seems that there is a limit to it. I just set a maximum number of parallel requests and the problem never appeared again.

Upvotes: 0

Vin&#237;cius Albino
Vin&#237;cius Albino

Reputation: 547

You can use

fetchRequest.returnsObjectsAsFaults = false

and as you access your object use

print(yourObject.valueForKey("yourKey")

Upvotes: 1

Related Questions