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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:49:29+00:00 2026-06-17T06:49:29+00:00

I’ve struggled with this all day using answers from here, but I cannot find

  • 0

I’ve struggled with this all day using answers from here, but I cannot find a solution that is working for me, so I thought I’d ask for help:

I have an array of objects that I’ve extracted from an entity.

All I want to do is to write the objects to a file.

What I’ve come up with so far is this:

    NSLog(@" Exported Records: %i", [exportArray count]); 
    // the count here is 4 records.
    //Each record has about 8 elements. 
//I'm just trying to get this working with the first two elements right now

        NSString *writeString = nil;
        NSError *error = nil;
        int i = 0;
        NSString *key = nil;
        NSString *tempString = nil;
        for (i=0; i<[exportArray count]; i++)
        {
            tempString = [tempString stringByAppendingString: @" \n "];

            for (int j=0; j<3; j++)
            {
                if (j == 0)
                {
                    key = [[exportArray objectAtIndex:i]  valueForKey:@"title"];
                    //[NSString stringWithFormat:tempString2, [[exportArray objectAtIndex:i]  valueForKey:@"title"]];
                }
                if (j == 1)
                {
                    key = [[exportArray objectAtIndex:i]  valueForKey:@"username"];
                    //[NSString stringWithFormat:tempString2, [[exportArray objectAtIndex:i]  valueForKey:@"username"]];
                }
                writeString = [NSString stringWithFormat:tempString, key];
            }
        }

        // Write to the file
        [writeString writeToFile:dataFile atomically:YES
                    encoding:NSUTF8StringEncoding error:&error];
        if (error)
        {
            NSLog(@"%@", error);
        }

Right now, all I’m getting the the last item, so I’m overwriting the string. But, there must be a better method to achieve this. Please let me know if there is another answer here matches my question, or please, post some ideas.

UPDATE

When I log the exportArray, I get this:

"<ItemEntity: 0x1ddf6560> (entity: ItemEntity; id: 0x1ddf46d0 <x-coredata://78FBC4A5-AE1A-4344-98AB-978126457D96/ItemEntity/p2> ; data: <fault>)",
    "<ItemEntity: 0x1ddf6800> (entity: ItemEntity; id: 0x1ddf46e0 <x-coredata://78FBC4A5-AE1A-4344-98AB-978126457D96/ItemEntity/p2051> ; data: <fault>)",
    "<ItemEntity: 0x1ddf6860> (entity: ItemEntity; id: 0x1ddf45d0 <x-coredata://78FBC4A5-AE1A-4344-98AB-978126457D96/ItemEntity/p3075> ; data: <fault>)",
    "<ItemEntity: 0x1ddf68c0> (entity: ItemEntity; id: 0x1ddf45e0 <x-coredata://78FBC4A5-AE1A-4344-98AB-978126457D96/ItemEntity/p5124> ; data: <fault>)"
)

When I log the actual values:

NSLog(@" Exported titles: %@", [exportArray valueForKey:@"title"]);
NSLog(@" Exported usernames: %@", [exportArray valueForKey:@"username"]);

I get correct results. I just don’t know how to tie these and the other attributes together..

  Exported titles: (
    1,
    2,
    4,
    6
)
  Exported usernames: (
    ellis,
    david,
    bea,
    ian
)
  • 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-17T06:49:30+00:00Added an answer on June 17, 2026 at 6:49 am

    If you just have NSDictionaries in your array, you can use writeToFile:atomically: which will save a file in .plist format (which is much easier to read than a CSV).

    Check out the Apple Docs for NSArray, and a good write up on plists.

    So you would end up having:

    [exportArray writeToFile:fileName atomically:YES];
    

    Edit: You cannot save a core data object to a file. So what you want to do is create an interim array with just the data you want, then write that to the file.

    NSMutableArray* arrayToSave = [NSMutableArray arrayWithCapacity:exportArray.count];
    [exportArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        NSDictionary* exportDict = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [obj objectForKey:@"username"], @"username",
                                    [obj objectForKey:@"title"], @"title", nil];
        [arrayToSave addObject:exportDict];
    }];
    
    [arrayToSave writeToFile:fileName atomically:YES];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this

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.