ios - Fetching particular attributes or properties in CoreData -
i using following code eliminate attributes while fetching coredatamodel called industry. still able access attributes have not requested using fetchrequest.propertiestofetch let fetchrequest = nsfetchrequest(entityname: "industry") fetchrequest.propertiestofetch = ["id","industry_name"]
after using following code: industryobject.industry_name=tuple.value(forkey: ""ind_subtype"") as? string "ind_subtype" have not specified in *.propertiestofetch* , still able access func fetchindustrynameswithid()->[industrydata]{ var industrydata=[industrydata]() //fetchrequest.predicate = nspredicate(format: "firstname == %@", firstname) let fetchrequest = nsfetchrequest<nsmanagedobject>(entityname: "industry") fetchrequest.propertiestofetch = ["id","industry_name"] { let tuples = try managedobjectcontext.fetch(fetchrequest) tuple in tuples{ let industryobject=industrydata() industryobject.id=tuple.value(forkey: "id") as? int industryobject.industry_name=tuple.value(forkey: "industry_name") as? string industryobject.ind_subtype=tuple.value(forkey: "ind_subtype") as? string industrydata.append(industryobject) } return industrydata } catch { let fetcherror = error nserror print(fetcherror) } return industrydata }
this how works. when set propertiestofetch
coredata returns managedobject partially faulted. means of properties populated not. when access property not populated, core data fulfil have performance impact because in cases require roundtrip row cache.
for more info google coredata faulting
Comments
Post a Comment