问题
I have asked reference question in this link.I got answer using NSMangedObjectID.Now I have used below function to get Component entity from its componentID.As in the API response of SyncSurveyWebReadings,I only get componentId,I need to fetch Component entity & set as relationship.Now time taking issue is not there.But may be relationship is not getting set.When I print the relationship object I got,
Optional<Array<SurveyReadingWeb>>
▿ some : 1 element
- 0 : <GazSurvey_Dev.SurveyReadingWeb: 0x282e0c8c0> (entity: SurveyReadingWeb; id: 0xf496ed8ab8c8dfd6 <x-coredata://3A27D5DB-BFBC-4005-BA69-59CB5C392617/SurveyReadingWeb/p4000> ; data: <fault>)
func getComponentFromID(compID : Int32) -> Components? {
var component :Components? = nil
var objectId : NSManagedObjectID? = nil
let fetchRequest = NSFetchRequest<NSManagedObjectID>(entityName: "Components")
fetchRequest.predicate = NSPredicate(format: "componentId == %ld", compID)
fetchRequest.resultType = NSFetchRequestResultType.managedObjectIDResultType
do {
objectId = try managedContext.fetch(fetchRequest).first
if objectId != nil {
component = managedContext.object(with: objectId!) as? Components
}
}
catch {
}
return component
}
来源:https://stackoverflow.com/questions/62169290/relationships-entitys-data-is-fault