Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8956123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:43:03+00:00 2026-06-15T14:43:03+00:00

This is my core data structure Entity – Category Attr – Id (NSString) primary

  • 0

This is my core data structure

Entity – Category

Attr – Id(NSString) primary key, name(NSString)

Entity – Product

Attr – Id(NSString), name(NSString), parentCategoryId(NSString) foreign key,….

As can be seen from above, Id from Category points to parentCategoryId from Product.

In this case, I want to use name from category associated with concerned parentCatrgoryId from product as my section name for UITableView.(I use @”parentCategoryId” as key to NSSortDescriptors in fetchrequest)
But parentCatrgoryId are simply alphanumeric texts.

How can I decode the the alphanumeric text i.e. parentCatrgoryId from product to name from category

EDIT

This is what I did & its working. But what I want to ask if what I did is efficient.

I added one more attribute named parentCategoryIdName & used this to store the exact name by computing some simple operation.

.h file

@property (nonatomic, retain) NSMutableArray *categoryArr;
@property (nonatomic, retain) NSMutableArray *productArr;

.m file

   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:&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:&error2] mutableCopy];
    [self setProductArr: mutableFetchResults2];

To insert the data in DB

    for (int i=0; i< [self.productArr count]; i++) {
        Product *productEnt = [self.productArr objectAtIndex:i];
        NSManagedObjectContext *context = self.MOContext;

            for (int j=0; j<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:&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();
            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:43:05+00:00Added an answer on June 15, 2026 at 2:43 pm

    to recap:
    From what I gather you need the id/name to form sections and show it in the section’s title.

    you solution would be efficient IMO but it should be the last resort:

    ideas:
    I would get the categoryName from categoryId JIT when you have to return the
    titleForSectionAtIndex:

    OR if that is too slow.

    fetch all section names when reloading the results.

    => Dont keep ’em in the database and duplicate data

    BUT

    if you see that it is really too slow, THEN denormalizing your data in that way is good IMO (it shoule be the last solution to consider)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this structure in a entity of core data: ID Region SubRegion SubRegionID
I have a Core Data model structure like the following: Product <-->> OrderProduct where
I am hitting this error when implementing core data. I have created a entity
I have this data structure: <estates version=0.1> <provider name=Foo> <estate id=12345678> <description>aaa</description> <size>300</size> </estate>
I have a data structure in Core Data like so... User Item Category User
In this test Core Data project, I have a one to many relationship from
this is my core data model: I'm trying to get all LanguageEntries from a
I used core data to do this: NSManagedObjectContext *m = [self managedObjectContext]; Foo *f
I am having my core data model like this: EntityA <---->> EntityB <<----> EntityC
I'm following this how-to to implement Core Data storage in my app: I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.