开发者

NSPredicate Query for Subsets and "Close Enough" Subsets

Bit new to NSPredicates and Core Data in general, so trying to grasp my head around need to do the following:

I have two Entities that have a Many-to-many relationship:

MyContainerEntity contains a many to many relationship with MyObjectEntity.

Say the list of MyObjectEntity is: A, B, C, D, E, F

And MyContainerEntity is made up of:

Container1 - A, B, C
Container2 - B, C, D
Container3 - A, B, D
Container4 - A, D, F

That is, Container1 contains a relationship with MyObjectEntity A, B and C and so on.

I would like to make a query w开发者_JS百科here I send in a list of MyObjectEntity and all MyContainerEntity objects that are a subset of that list are returned.

For example:

(A,B,D,F) would return Container3, and Container4.

Then the follow up would be getting something that is "close" with some error value. Say only 1 object missing. For example:

(A, B) would return Container1 and Container3

Any help would be greatly appreciated.


To get the first part of your problem, have you tried defining a predicate such as:

ALL objects IN $OBJECTS_PARAM

where OBJECTS_PARAM value would be an array or set that you pass into to the evaluation via a "predicateWithSubstitutionVariables" argument?

For the follow up question, I'm not sure if it is possible directly in a predicate. It seems like it might be better to implement such a query manually in code rather than relying on an NSPredicate to do that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜