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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:56:17+00:00 2026-05-25T00:56:17+00:00

I’m trying to write data from an NSMutableArray into a core data table via

  • 0

I’m trying to write data from an NSMutableArray into a core data table via an NSManagedObject for loop. It writes out the last record in the the array multiple times rather than writing out each of the distinct rows in the array.

I’ve done a fast enumeration loop on the array to confirm it has multiple distinct rows.

This is the current version of my code loop:

  //see if there were any matching rows from All_Game_Tips_List entity and of course there should be 
if (fetchedObjectsForAttributes == nil) {
    // do nothing as user1 does not have a saved profile
    NSLog(@"error no matching rows found which sounds suspect");
}
else 
{
    for (id object in fetchedObjectsForAttributes ) {
        NSLog(@"alltip_obj = %@", object);

    NSLog(@"found exactly %i matching alltip records",[fetchedObjectsForAttributes count]);                                                                                  

//next need to write a couple of fields from the profile entity and some from All_Game_Tips_List entity to mytips table  but first need to get all needed attributes for an attribute (e.g. name, tminus, etc) for an attribute
//then insert the new row
NSManagedObjectContext *contextForMyTips = [appDelegate managedObjectContext];   


NSManagedObject *myTipsFromAllTips = [NSEntityDescription
                                         insertNewObjectForEntityForName:@"My_Game_Tips_List" 
                                         inManagedObjectContext:contextForMyTips];
NSLog(@"start wri to mytips");

for (NSManagedObject *info in fetchedObjectsForAttributes) {
    [myTipsFromAllTips setValue:[info valueForKey:@"alltip_name"]               forKey:@"mytip_name"];
    [myTipsFromAllTips setValue:[info valueForKey:@"alltip_alert_msg"]          forKey:@"mytip_alert_msg"];
    [myTipsFromAllTips setValue:[info valueForKey:@"alltip_description"]        forKey:@"mytip_description"];
    [myTipsFromAllTips setValue:[info valueForKey:@"alltip_id"]                 forKey:@"mytip_id"];
    [myTipsFromAllTips setValue:[info valueForKey:@"alltip_tminus_amt"]         forKey:@"mytip_tminus_amt"];
    [myTipsFromAllTips setValue:[info valueForKey:@"alltip_impact_type"]        forKey:@"mytip_impact_type"];


}    // end of for NSManagedObject loop

        //commit the insert
        if (![contextForMyTips save:&error]) {
            NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
        }
}    // looping through id 

}    // end of else

Thoughts on why it’s stuck on the last record in the array?

  • 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-05-25T00:56:18+00:00Added an answer on May 25, 2026 at 12:56 am

    This is because circle

    for (NSManagedObject *info in fetchedObjectsForAttributes) {
    

    saves only last object, as it rewrites all previously set data.
    Just replace that loop with that one:

    NSManagedObject *info = (NSManagedObject *)object;
    

    And all will be ok as circle

    for (id object in fetchedObjectsForAttributes ) {
    

    will iterate objects one by one.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6

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.