Relationship's entity's data is <fault>

假装没事ソ 提交于 2020-06-17 09:44:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!