54

I have found a few questions regarding this issue, yet none of them were helping with my problem. I am trying to save an object to core data using this code (which worked perfectly fine in Xcode 6 and Simulator...):

let fetchRequest = NSFetchRequest(entityName: "Patient")
let fetchedResults : [NSManagedObject]!
do {
    fetchedResults = try managedContext.executeFetchRequest(fetchRequest) as! [NSManagedObject]
    patienten = fetchedResults
}    catch {
    print("error")
}

I added the do-try-catch once I started working on this project in the Xcode 7 beta and a physical device. Now, when I hit the Save button, this piece of code is called, the app freezes and I get the following:

warning: could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available.

Screenshot

Does anybody know where I went wrong?

Jayprakash Dubey
  • 32,447
  • 16
  • 161
  • 169
zero
  • 705
  • 1
  • 5
  • 12
  • I would suggest changing your print statement to actually printing out the error: `print("Error: \(error)")` and then see what the actual error is. – Marcus S. Zarra Jul 15 '15 at 15:09
  • The warning you got tends to happen whenever you use swift in the current version of Xcode. It may or may not be related to your problem. – whoKnows Oct 07 '15 at 11:55

5 Answers5

23

For anyone coming across this in the future, I just ran into this problem myself and it turned out that I was actually getting a stack overflow from a recursive function.

Apparently calling setValue:forKey: on an NSObject calls the respective set[Key] function, where [Key] is the (capitalized) name you gave to the forKey section.

So, if like me, you have code that looks like the following, it will cause an infinite loop and crash.

func setName(name: String) {
    self.setValue(name, forKey: "name")
}
thislooksfun
  • 896
  • 9
  • 23
  • 4
    Had a different scenario, but same problem, infinite recursion. The error is totally misleading. +1 – oarfish Feb 23 '16 at 17:41
  • :) had also same but i am adding dictionary object into the same dictionary like NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; [dict setValue:dict forKey:API_PARAM]; – Jageen Mar 04 '16 at 05:41
14

Choose Product > Clean

I had similar issue. I deleted the app from the device. Then "Product->Clean" in the XCode menu. When I ran the app again, the issue got resolved.

Basil Bourque
  • 218,480
  • 72
  • 657
  • 915
Big D
  • 357
  • 3
  • 6
  • Thanks fixed it for me too, on XCode Version 7.2.1 (7C1002) – malhal Feb 10 '16 at 23:50
  • Issue fixed this way on XCode v7.3.1 – Richard Jun 06 '16 at 19:34
  • 1
    Fixed it for me too. Should be the accepted Answer. Another symptom of the problem: NSSet and NSArray did not expose their elements in the debugger’s Variables/Values pane. After a Product > Clean, (a) error message disappeared, and (b) collection elements appeared in pane. – Basil Bourque Aug 23 '16 at 01:16
1

Swift 3:

Actually this problem happened often when you have any property in input declared as type NSError and the compiler expect an Error output, so change the input type to Error usually solve this issue.

Alessandro Ornano
  • 31,579
  • 11
  • 90
  • 115
0

What helped me in similar problem (xCode 7, Swift 2):

reading this question

Or more quickly without explaining the reason of solution: just comment @objc(className) in your NSManagedObjectSubclass , that was generated from your CoreData Entity (@objc(Patient) - in your case ).

This solution (if issue still appears) does not applicable to xCode 7.1/Swift 2.1, as the way of generating NSManagedObjectSubclasses was changed.

Don't forget about cleaning your project (Product > Clean) and deleting the app from your device/simulator to replace CoreData storage on it.

Community
  • 1
  • 1
Yurii Koval
  • 389
  • 4
  • 15
-1
let fetchRequest = NSFetchRequest(entityName: "Patient")

do {
  let fetchedResults = try managedObjectContext!.executeFetchRequest(fetchRequest)
  print("\(fetchedResults)")
} catch {
  print("error")
}

The above code worked for me. Maybe the issue maybe with how your core data is managed.

  1. Check if your managedObjectContext is actually getting created.
  2. Check the modelling of your core data
rkyr
  • 2,951
  • 2
  • 19
  • 36