Note that there are some explanatory texts on larger screens.

plurals
  1. PONSFetchedResultsController sections name - Tracking EFFICIENCY
    primarykey
    data
    text
    <p>This is my core data structure</p> <p>Entity - <strong>Category</strong></p> <p>Attr - <strong>Id</strong>(NSString) <strong><em>primary key</em></strong>, <strong>name</strong>(NSString)</p> <p>Entity - <strong>Product</strong></p> <p>Attr - <strong>Id</strong>(NSString), <strong>name</strong>(NSString), <strong>parentCategoryId</strong>(NSString) <strong><em>foreign key</em></strong>,....</p> <p>As can be seen from above, <em>Id from Category</em> points to <em>parentCategoryId from Product</em>.</p> <p>In this case, I want to use <em>name from category</em> associated with concerned <em>parentCatrgoryId from product</em> as my section name for UITableView.(I use @"parentCategoryId" as key to NSSortDescriptors in fetchrequest) But <em>parentCatrgoryId</em> are simply alphanumeric texts.</p> <p>How can I decode the the alphanumeric text i.e. <em>parentCatrgoryId from product</em> to <em>name from category</em></p> <p><strong>EDIT</strong></p> <p><em><strong>This is what I did &amp; its working. But what I want to ask if what I did is efficient.</em></strong></p> <p>I added one more attribute named <strong>parentCategoryIdName</strong> &amp; used this to store the exact name by computing some simple operation.</p> <p>.h file</p> <pre><code>@property (nonatomic, retain) NSMutableArray *categoryArr; @property (nonatomic, retain) NSMutableArray *productArr; </code></pre> <p>.m file</p> <pre><code> NSEntityDescription *entity = [NSEntityDescription entityForName:@"Category" inManagedObjectContext:self.MOContext]; // Setup the fetch request NSFetchRequest *request = [[NSFetchRequest alloc] init]; [request setEntity:entity]; // [request setPredicate:[NSCompoundPredicate andPredicateWithSubpredicates:subpredicates]]; NSError *error; NSMutableArray *mutableFetchResults = [[self.MOContext executeFetchRequest:request error:&amp;error] mutableCopy]; [self setCategoryArr: mutableFetchResults]; NSEntityDescription *entity2 = [NSEntityDescription entityForName:@"Product" inManagedObjectContext:self.MOContext]; // Setup the fetch request NSFetchRequest *request2 = [[NSFetchRequest alloc] init]; [request2 setEntity:entity2]; // [request2 setPredicate:[NSPredicate predicateWithFormat:@""]]; NSError *error2; NSMutableArray *mutableFetchResults2 = [[self.MOContext executeFetchRequest:request2 error:&amp;error2] mutableCopy]; [self setProductArr: mutableFetchResults2]; </code></pre> <p>To insert the data in DB</p> <pre><code> for (int i=0; i&lt; [self.productArr count]; i++) { Product *productEnt = [self.productArr objectAtIndex:i]; NSManagedObjectContext *context = self.MOContext; for (int j=0; j&lt;self.categoryArr.count; j++) { Category *categroy = [self.categoryArr objectAtIndex:j]; if ([categroy.objectId isEqualToString:productEnt.parentCategoryId]) { [productEnt setParentCategoryIdName:categroy.name]; } // Save the context. NSError *error = nil; if (![context save:&amp;error]) { // Replace this implementation with code to handle the error appropriately. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload