Swift RestKit CoreData - RKEntityMapping class nil for class name

Using RestKit and CoreData with Swift

RestKit offers functionality for directly binding JSON to NSManagedObject instances. You use the following line of code to initialize the RKEntityMapping object:

var classMapping :RKEntityMapping = RKEntityMapping(forEntityForName:"className",inManagedObjectStore:managedObjectStore) 

This leads to the following error: The application terminated due to the uncaught exception "NSInternalInconsistencyException", reason: "Unable to initialize entity mapping for object with nil managed object class: Got nil class for managed object class name" className ". Maybe you forgot to add class files to your goal?

The error occurs because of this line in the RestKit API:

 Class objectClass = NSClassFromString([entity managedObjectClassName]); 

Decision:

If your NSManagedObject class is written in Swift, you must add the following code before declaring the class:

 @objc(className) class className { ... } 

Hope this helps!

+7
mapping swift core-data restkit
source share

No one has answered this question yet.

See related questions:

902
# pragma in Swift?
3
RestKit + CoreData, understanding of RKManagedObjectRequestOperation
2
Swift CoreData Failed to Call Assigned Initializer on NSMangedObjectClass
2
restkit mapping and feedback
2
RestKit: mapping class is null in Swift
2
Mix NSManagedObjects and regular objects in RestKit
0
FetchRequest does not return NSManagedObjects retrieved through RestKit 0.2
0
RestKit 0.20 - CoreData: error: Failed to call the designated initializer in the NSManagedObject class (again)
0
RestKit - multi-type display of subarrays
0
CoreData with RestKit

All Articles