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

  • Home
  • SEARCH
  • 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 502271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:16:27+00:00 2026-05-13T06:16:27+00:00

I have a problem that whenever I’m inserting data using coredata, everything’s going fine.

  • 0

I have a problem that whenever I’m inserting data using coredata, everything’s going fine. But while retrieving, I’m getting the same object all the time retrieved. I’m inserting objects of actors with multiple attribues like id,name,address etc. in add method, I can see everything getting inserted(which actually I’m retrieving from an xml file). my set methods are like:=

[poi setActorCity:[NSString stringWithFormat:@"%@",[poi1 objectAtIndex:j]]];

where, poi is an object of my managedObjectClass POI1 . Are those a problem? & j index is simply for keeping track of xml values from poi1 array. Please help…

  • (void)addEvent
    {

[actorsArray removeAllObjects];

NSEntityDescription *entity1 = [NSEntityDescription entityForName:@”POI1″ inManagedObjectContext:self.managedObjectContext];

POI1 *poi = (POI1 *)[NSEntityDescription insertNewObjectForEntityForName:@”POI1″ inManagedObjectContext:managedObjectContext];

for(NSInteger i=0;i<[Actors count];i++)
{
    NSMutableArray *poi1=[[NSMutableArray alloc]init];
    poi1=[Actors objectAtIndex:i];
    for(int j=0;j<[poi1 count];j++)
    {
        if(j==1)
        {
            [poi setActorName:[NSString stringWithFormat:@"%@",[poi1 objectAtIndex:j]]];

        } //Like this it inserts for every attribute
            }
    [actorsArray insertObject:poi atIndex:i];       
    [poi release];
}
[self saveAction]; //saving the managedObjectContext

}

This’ my fetch method…

-(void)fetchResult
{

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSEntityDescription *entity1 = [NSEntityDescription entityForName:@”POI1″ inManagedObjectContext:self.managedObjectContext];

[fetchRequest setEntity:entity1];

NSArray *items = [self.managedObjectContext
              executeFetchRequest:fetchRequest error:&error];

for(NSInteger k=0;k<[items count];k++)
{
    POI1 *_poi=[[POI1 alloc]init];
        _poi = [items objectAtIndex:k];
         NSString *str=[NSString stringWithFormat:@"%@",[_poi actorName]]; //This' for testing... Shows me same name every time..,
}

[fetchRequest release];     

}

  • 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-13T06:16:27+00:00Added an answer on May 13, 2026 at 6:16 am

    It sounds like you have a problem with your fetch. Check your predicate. If it returns the same object the most likely cause is that your predicate is written such that it only finds that one object.

    Edit01:

    This line is your problem:

    POI1 *poi = (POI1 *)[NSEntityDescription insertNewObjectForEntityForName:@"POI1" inManagedObjectContext:managedObjectContext];
    

    Despite the fact that the class called is ‘NSEntityDescription’ this method returns a managed object instance. Right now you create a single POI1instance and then just keep assigning it different attributes. You’re seeing the same values because you’ve only created, populated and saved one object.

    Move the object creation inside the loop:

    for(NSInteger i=0;i<[Actors count];i++)
    {
            POI1 *poi = (POI1 *)[NSEntityDescription insertNewObjectForEntityForName:@"POI1" inManagedObjectContext:managedObjectContext];
            NSMutableArray *poi1=[[NSMutableArray alloc]init];
            poi1=[Actors objectAtIndex:i];
            for(int j=0;j<[poi1 count];j++)
            {
                    if(j==1)
                    {
                            [poi setActorName:[NSString stringWithFormat:@"%@",[poi1 objectAtIndex:j]]];
    
                    } //Like this it inserts for every attribute
                            }
            [actorsArray insertObject:poi atIndex:i];               
            [poi release];
    }
    

    This will create a new POI1 at each pass so that the each element of the Actors array will have a corresponding POI1 instances containing its data.

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

Sidebar

Ask A Question

Stats

  • Questions 291k
  • Answers 291k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use the DataTableExtensions extension methods to convert the DataTable to… May 13, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer Can't I cast the two-dimensional-array to a flat one-dimensional-array Technically… May 13, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer Since more than one record in t_large may correspond to… May 13, 2026 at 5:59 pm

Related Questions

I have a situation where I have an interface that defines how a certain
I have a persistent class Author with two fields: int id , String name
I am making a very simple platform independent(at least that's the plan) console app.
We have several SQL Server 2000 databases (I know, we need to upgrade) that
Firstly, let me set out what I'd like to do. Assume I have three

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.