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 7780151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:49:19+00:00 2026-06-01T18:49:19+00:00

I am learning CoreData with a sample inventory app. My Data Model has 2

  • 0

I am learning CoreData with a sample inventory app. My Data Model has 2 entities, “Possession” and “Asset Type”. Possessions have a to-one relationship to Asset Types called “assetType” and Asset Types have a to-many relationship to Possessions named “possessions”. Each Possession has only one Asset Type, but Asset Types have many Possessions.

I’d like to sort a tableview into sections based on asset types. I need some help populating my data structure for this though.

Here is how I’ll model my table view controller

NSArray for table sections
each section object in the array will be an NSDictionary with 2 keys, @”Header” – which will be the Asset Type, and @”Possessions” which is an array of possessions of that asset type.

I can handle building my table view from this structure no problem. I can also handle fetching the Asset Types from CoreData into the header key of my dictionary. Where I am stumped is how do I take advantage of the to-many relationship that asset types have to possessions so I can get the possessions into an array for the dictionary.

How do I get each Asset Type’s possessions into an array?

Do I need to make a fetch request with a predicate to fetch possessions that have the matching asset type, or is there a simpler way? – Seems that would be inefficient as it would have to check all possessions for a match!?!?!?!?

Is the to-many relationship “possessions” of AssetType entity an accessible property of the AssetType entity? If so how do I access it? What does it return?

I am not looking for free code, but I am willing to post mine if needed. What I’d really like is to know the best way to solve this problem and maybe pointed to helpful info online to accomplish this. I am not a complete newb, but I am still having trouble wrapping my head around CoreData and thus far the Apple docs are still pretty confusing to me on this subject. I am appreciative for any help offered.

  • 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-01T18:49:20+00:00Added an answer on June 1, 2026 at 6:49 pm

    If you’ve created your AssetType class with Xcode default NSManagedObject template (see image)

    File/New/File.../Core Dats/NSManagedObject subclass

    you should have something like that in your AssetType.h:

    @interface AssetType : NSManagedObject
    
    @property (nonatomic, retain) NSSet *possessions;
    
    @end
    
    @interface AssetType (CoreDataGeneratedAccessors)
    
    - (void) addPossessionsObject:    (Possession *) value;
    - (void) removePossessionsObject: (Possession *) value;
    - (void) addPossessions:          (NSSet *) value;
    - (void) removePossessions:       (NSSet *) value
    
    @end
    

    So if you have an AssetType object, you can access all Possession objects related to it via the possessions property. It is not ordered by default though, so to access these objects as an array, you will need to call the -allObjects method of the set which returns the objects within the set as an array and then probably sort these objects somehow.

    Edit:

    Also, even if you did not create the NSManagedObject subclass that way and it does not have the possessions property implemented yet, you could add this property to the class in the just same way as stated in the example above and implement it within the AssetType.m as @dynamic possessions.

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

Sidebar

Related Questions

I am learning to use Core Data. I have created a data model etc
I am using Apple's CoreDataBooks sample project as a learning aid for core data.
I'm just getting started learning CoreData for iOS and have written some exploratory code
learning Jquery and integrating with PHP - getting there, but have one last challenge
Learning C# here. I have a monthly process form whereby one can select to
I have been learning CoreData to use it in my application and have some
I'm just learning core data and mostly coping, but having a little bit of
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
I need your help, I'm learning the coreData migration and I can't access to
I am just learning Core Data on iPhone and the tutorial I am following

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.