I am getting an error:
One or more of the following type_info's has hidden visibility or is defined in more than one translation unit. They should all have public visibility. N10__cxxabiv116__shim_type_infoE, id,
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The fetch request's entity 0x28360c160 'CustomModel' appears to be from a different NSManagedObjectModel than this context's'
Here is my subclass:
import Foundation
import CoreData
public class CustomModel: NSManagedObject, Identifiable {
@NSManaged public var name: String?
@NSManaged public var select: Int
}
extension CustomModel {
static func allCustomModelFetchRequest() -> NSFetchRequest<CustomModel> {
let request: NSFetchRequest<CustomModel> = CustomModel.fetchRequest() as! NSFetchRequest<CustomModel>
request.sortDescriptors = [NSSortDescriptor(key: "CustomModel", ascending: true)]
return request
}
static func queryCustom(name:String) -> NSFetchRequest<CustomModel> {
let request: NSFetchRequest<CustomModel> = CustomModel.fetchRequest() as! NSFetchRequest<CustomModel>
request.predicate = NSPredicate(format: "name == %@",name)
request.sortDescriptors = [NSSortDescriptor(key: "CustomModel", ascending: true)]
return request
}
}
let results = CustomModel.queryCustom(name: name)
do {
let results = try viewContext.fetch(results)
} catch let err as NSError {
}
Here is my entire debug window:
2022-04-02 17:37:49.398556+0800 double[47397:10198283] dynamic_cast error 2: One or more of the following type_info's has hidden visibility or is defined in more than one translation unit. They should all have public visibility. N10__cxxabiv116__shim_type_infoE, id, N10__cxxabiv117__pbase_type_infoE.
2022-04-02 17:37:49.398743+0800 double[47397:10198283] dynamic_cast error 2: One or more of the following type_info's has hidden visibility or is defined in more than one translation unit. They should all have public visibility. N10__cxxabiv116__shim_type_infoE, id, N10__cxxabiv117__pbase_type_infoE.
2022-04-02 17:37:50.442791+0800 double[47397:10198283] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The fetch request's entity 0x28360c160 'CustomModel' appears to be from a different NSManagedObjectModel than this context's'
*** First throw call stack:
(0x1812010fc 0x199a51d64 0x1887ea400 0x1887fea60 0x1f191cf3c 0x104e1e8f8 0x104e1e16c 0x104e1e270 0x183775250 0x1837a7d8c 0x1837b4f2c 0x183964e34 0x183788140 0x18377cf2c 0x1837823d8 0x1812230d0 0x181233d90 0x18116e098 0x1811738a4 0x181187468 0x19cd2b38c 0x183b2a5d0 0x1838a8f74 0x188e46314 0x188d75508 0x188d56cb8 0x104eecfa8 0x104eed21c 0x1071d9aa4)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The fetch request's entity 0x28360c160 'CustomModel' appears to be from a different NSManagedObjectModel than this context's'
terminating with uncaught exception of type NSException
Message from debugger: failed to send the k packet