ios - Fetching only Core Data objects that share a value for a particular attribute -


I have a core data object that has many attributes, one of which is called a category. It is a string that can be taken at any price, nothing is guaranteed that I have any knowledge of the front. I will run a fetch that will return a list of category values ​​that are shared in all stored elements whose tag values ​​match a given value. I'm not sure how to best describe, here's an example:

  item number tag category ------------------- - ------------ 01 AAA Red 02 AAA Green 03 AAA Blue 04 BBB Blue 05 BBB Red 06 BBB Yellow 07 CCC Blue 08 CCC Yellow 09 CCC Red  
< P> I want to keep the results of my fetch as a list of all the categories that are shared in all objects whose tag set {AAA, BBB, CCC }, Who will return ["red", "blue"] in this case, because they are only one of those categories which is shared between objects, whose tag is in the set set.

I hope to find something as fast as possible, because when this app runs on any real project, there will be thousands of objects in the database. Here is a code sample which I just wrote, that Sho Yld solved my filtration question.

I'm still learning the complexities of NSFetchRequest and predicates, even though it is not very complicated, after reading documents and using the experiment.

  NSArray * setsoftags = [NSARRAABRID: @ "AAA", @ "BBB", Nil]; NSFetchRequest * request; NSMutableSet * tagsSenetsetset = Zero; {NSString * tags in settings] {request = [NSFetchRequest fetchRequestWithEntityName: @ "ObjectWithCategories"]; NSPredicate * tagPredicate = [NSPredicate predicateWithFormat: @ "% K ==% @", @ "tag", tag]; Request.predicate = tagPredicate; NSArray * objects; NSError * err; NSMutableSet * Tag Category = [[NSMutableSet alloc] initWithCapacity: 1]; If ((Object = [Self-Management Object Object Compact Extrab FetcherQuest: Request Error: & amp; Error]) == zero) {// Error NSLog (@ "There was an error: \ n% @", [in Local Diesition mistake]); } Else {// fetch request succeeded // If ([Objects counting] == 0) continue, then ignore any unused tags; // Assemble the Category attribute for an unstable set (Object in the NSMNEZ object * Obj) {[Tagcreds adobject: [(ID) OBG category]]; } // Assign the first, later intersect tag credentials if (tagiczsetset == zero) {tagcategoriesset = tagcategories; } And {{tagcargesetsetsetsetsetset: tagscragens]; }}} NSArray * Ultimate Categories = [Tag Suggestions of All Objects];  

Here's another Q & A for further discussion:


Comments

Popular posts from this blog

Editing Python Class in Shell and SQLAlchemy -

import - Python ImportError: No module named wmi -

uislider - In a MATLAB GUI, how does one implement a continuously varying slider from a GUIDE created .m file? -