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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:40:27+00:00 2026-05-23T20:40:27+00:00

I am wondering how I can programmatically update a Core Data object. The object

  • 0

I am wondering how I can programmatically update a Core Data object. The object is a NSSet though. So I can summarize this with the scheme below:

Property
---------
name
price
typology

Property_has_typology
---------------------
typology_id
property

There is a one-to-many relationship between the Property and Property_has_typology. As one property might have several typologies (aka categories) such as Bed & Breakfast, Villa, Hotel, Mansion, Country House.

So I let the user select multiple rows in my TableView and when he clicks save I want to store these changes. So I do:

NSMutableArray *storeItems = [[NSMutableArray alloc] init];

//Get selected items
for (int i = 0; i < [items count]; i++) {
     Properties_has_typology *typo = [NSEntityDescription insertNewObjectForEntityForName:@"Properties_has_typology" 
                                                                    inManagedObjectContext: [PropertyProvider sharedPropertyProvider].context];
     typo.typology_id = [NSNumber numberWithInt: (int)[items objectAtIndex:i]];
     typo.property = property;
     [storeItems addObject: typo];
}

//Store the items for the Property and save it
if ([storeItems count] > 0) {
    NSLog(@"Going to save...");
    NSSet *storeSet = [[NSSet alloc] initWithArray:storeItems];
    property.typology = storeSet;

    [property save];

    [storeSet release];
}

This kinda works, the issue though is that it doesn’t really update the existing values. It just overrides it. So if I save the same two items twice (just as an example) I’d get the following in my database:

PK  TYPOLOGY
------------
1 | 
2 |   
3 |  4
4 |  6

So yes they are being stored, but it also creates empty rows (clears them instead of deleting/updating them).

Any help would be appreciated. Thanks!

  • 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-23T20:40:27+00:00Added an answer on May 23, 2026 at 8:40 pm
    //call 
    NSArray* oldTypos = [property.typology allObjects];
    [[property removeTypology:[PropertyProvider sharedPropertyProvider].context];
    [[property addTypology:storeSet];
    for(int i = 0; i < [oldTypos count]; i++){
    [[PropertyProvider sharedPropertyProvider].context deleteObject:[oldTypos:objectAtIndex:i]];
    }
    Error* error = nil;
    if(![[PropertyProvider sharedPropertyProvider].context save:&error]){
    abort();
    }
    //Also, rename the to-many relationship to plural.
    

    Apologies of there are any typos. I am on my windows machine at the moment so I cannot check it.

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

Sidebar

Related Questions

Wondering if anyone can help me with this annoying but trivial (in terms of
I was wondering how can I programmatically copy all the discussion items from one
I have a UINavigationController, and I was wondering how I can programmatically tell when
I was wondering how can I set a timeout on a socket_read call? The
I'm wondering how can I submit a form via Ajax (using prototype framework) and
I'm wondering how you can implement a program similar to tail -f in C/C++,
I was wondering how i can force a user who has requested a page
I'm wondering if people can suggest the best tutorial that will walk me through
I am wondering if someone can put a bit of an authoritative reference summary
I'm wondering if anyone can recommend a good C++ tree implementation, hopefully one that

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.