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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:03:12+00:00 2026-06-12T11:03:12+00:00

I have a very simple app that has one CoreData Entity with a circular

  • 0

I have a very simple app that has one CoreData Entity with a circular relationship to itself. I want to use this data as a plist in another app.

The relationship is ‘to one’ on the parent side & ‘to many’ on the child side.

Basically a tree with one item at the top and then children of that object, children of the child objects, etc…

I want to create a dictionary/pList from this data with the structure of the entity including the relationships. (Does that make sense?)

So far, with the help of other answers here, I can get a plist of all the objects (but all on the same “level”) or a plist of the ultimate parent object (but the children relationship is faulted).

This is what I’m doing to try and get the data and save it to my desktop:

    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:ENTITY_NAME];
    request.resultType = NSDictionaryResultType;

    NSError *fetchError = nil;
    NSArray *results = [self.databaseDocument.managedObjectContext executeFetchRequest:request error:&fetchError];

    NSLog(@"%@", results);

    NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    NSString *path = [caches stringByAppendingPathComponent:@"/../../../../../../../../Desktop/my.plist"];
    [results writeToFile:path atomically:NO];

At the moment there are only three objects. A main object, a child of that object, and a child of that child object.

This is giving me an plist which is an array with three objects in it.

If I include a predicate to only get the object that has no parent like this:

    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:ENTITY_NAME];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"parent == nil"];
    request.predicate = predicate;

    NSError *fetchError = nil;
    NSArray *results = [self.databaseDocument.managedObjectContext executeFetchRequest:request error:&fetchError];

    NSLog(@"%@", results);

    Item *mainItem = [results lastObject];

    NSArray *keys = [[[mainItem entity] attributesByName] allKeys];
    NSDictionary *dict = [mainItem dictionaryWithValuesForKeys:keys];

    NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    NSString *path = [caches stringByAppendingPathComponent:@"/../../../../../../../../Desktop/my.plist"];
    [dict writeToFile:path atomically:NO];

This gives me a directory but does not include the children.

Can anyone explain to me how I can get the plist structured like my entity is? In other words just one Directory with all the children contained within, and the children of each child within the Directory for that child, and so on…?

  • 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-12T11:03:14+00:00Added an answer on June 12, 2026 at 11:03 am

    There may well be a better way to export your Core Data entities to a plist while preserving the hierarchical structure of the relationships – I’m willing to be educated. I would approach processing them in a recursive method like this: (this is completely untested – meant only for illustrative purposes – also I’m not completely sure how you want the plist structured, etc.)

    - (void)processEntity:(NSManagedObject *)object forMutableArray:(NSMutableArray *)mutableArray {
        NSMutableDictionary *entityInfo = [NSMutableDictionary new];
    
        // populate entityInfo with your object's properties
        // however you are doing that now...
    
    
        //  if this object has children - process them
        NSMutableArray *childArray = [NSMutableArray new];
        for( id child in object.children ) {
            [self processEntity:child forMutableArray:childArray];
        }
    
        [entityInfo setObject:childArray forKey:@"children"];
        [mutableArray addObject:entityInfo];
    }
    

    So, you start the process by iterating over the top-level objects (those with no parent) then process them in processEntity:forMutableArray:

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

Sidebar

Related Questions

I have a very simple Mac Cocoa app that just has a Web View
I need to create a very simple app that has one table that will
I have a table in my android app that is very simple. Has an
I have a very simple webforms app that will allow field techs to order
I have a very simple iPhone app that requires a random integer from 1-100.
I have two very simple, identical UITableViews in my app that are populated with
I'm working on a very simple iPhone app, that in the end will have
I have a very simple node.js app built on express which has been handling
I have created very simple app with persistence context (hibernate as provider) to read
I have a very simple OpenRasta app with a Home resource with a single

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.