I get the following error trying to run my application
fatal error: use of unimplemented initializer 'init(entity:insertIntoManagedObjectContext:)' for class 'rcresttest.CatalogItem'
I can bypass this error by changing the Entity's class in the data model to something else, but then I will get a swift_dynamicCastClassUnconditional: when trying to downcast.
Is this a bug in beta6 or am I doing something wrong?
CatalogItem.swift
import CoreData
@objc(CatalogItem)
class CatalogItem : NSManagedObject {
@NSManaged var id : String
@NSManaged var slug : String
@NSManaged var catalogItemId : String
init(entity: NSEntityDescription!, context: NSManagedObjectContext!, catalogResultsDict : NSDictionary) {
super.init(entity: entity, insertIntoManagedObjectContext: context)
id = catalogResultsDict["Id"] as String
slug = catalogResultsDict["Slug"] as String
catalogItemId = catalogResultsDict["CatalogItemId"] as String
}
}
and the data model
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="6220.8" systemVersion="13E28" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
<entity name="CatalogItem" representedClassName="CatalogItem" syncable="YES">
<attribute name="catalogItemId" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="id" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="slug" optional="YES" attributeType="String" syncable="YES"/>
</entity>
<elements>
<element name="CatalogItem" positionX="-45" positionY="0" width="128" height="90"/>
</elements>
</model>
Edit:
After changing the name of the datamodel class to have the module prefix The error message appears after trying to cast.
2014-08-20 10:49:15.335 rcresttest[63516:4194127] CoreData: warning: Unable to load class named 'rcresttest.CatalogItem' for entity 'CatalogItem'. Class not found, using default NSManagedObject instead.
This is a problem with the designated initializer. Just add convenience
in front of your init
and call init(entity:insertIntoManagedObjectContext:)
on self
instead super
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With