predicate with avoid child entity iOS swift

 Problem:

I had my coredata entity that main entity had one level of subentity with the same entity.But in predicate i want to avoid the subentity entry but if subentity has the predicated text then main entity wants to be came.How can i achieve that?


Solution:

First you have to add issubentity in the coredata entity and enter if subentity then true otherwise it will be false.Then follow the below code.

                    predicateStringAdd.append(NSPredicate(format"(time.startsOn >= %@ OR ANY subEntity.time.startsOn >= %@) AND isSubEntity != true",time1,time2))


the above will be based on start above start time and below endtime.


You can check with string as like below


                    predicateString.append(NSPredicate(format"(name CONTAINS[c] %@ OR  ANY subEntity.name CONTAINS[c] %@ OR desc CONTAINS[c] %@ OR ANY subEntity.desc CONTAINS[c] %@ AND isSubEntity != true",trimmedString,trimmedString,trimmedString,trimmedString))



Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Saved Image in document directory and save path in coredata not able to fetch the image file iOS swift