Crash when using Core Data from Playground
| Originator: | mprudhom | ||
| Number: | rdar://18846250 | Date Originated: | |
| Status: | Resolved: | ||
| Product: | Xcode | Product Version: | Xcode Version 6.1 (6A1052d) |
| Classification: | Crash/Hang/Data Loss | Reproducible: | Always |
Core Data works from the playground when there are no entities that use specific managed object subclasses, but when you set a managedObjectClassName in any of the entities, it crashes with: "Execution was interrupted, reason: EXC_BAD_ACCESS". This happens both when you define the NSManagedObject subclass in the playground itself or when you are referencing one that is contained in a module that was loaded in the playground.
To Reproduce:
Paste the following code into the Playground (either iOS or OSX) and observe the crash. Note that commenting out the "entity.managedObjectClassName = className" line lets it succeed.
import Foundation
import CoreData
@objc class SomeEntity : NSManagedObject {
@NSManaged var stringField: String
}
let mom = NSManagedObjectModel()
let entity = NSEntityDescription()
entity.name = "SomeEntity"
let className = NSStringFromClass(SomeEntity.self)
entity.managedObjectClassName = className
let attr = NSAttributeDescription()
attr.name = "stringField"
attr.attributeType = NSAttributeType.StringAttributeType
entity.properties = [attr]
mom.entities = [entity]
let ctx = NSManagedObjectContext()
let ob = NSManagedObject(entity: entity, insertIntoManagedObjectContext: ctx)
ob.setValue("This is some string", forKey: "stringField")
ob.valueForKey("stringField")
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!