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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:19:30+00:00 2026-05-14T07:19:30+00:00

I parse an xml file containing books, for each new node I go: Book

  • 0

I parse an xml file containing books, for each new node I go:

Book *book = (Book*)[NSEntityDescription insertNewObjectForEntityForName:@"Book" inManagedObjectContext:managedObjectContext];

To obtain an NSManagedObject of my Core Data Book Entity, I then proceed to populate the managed Book object with data, add it to an array, rinse, repeat.

When I am done, I present the list of books to the user.
I have not yet executed the save:

NSError *error;
if (![managedObjectContext save:&error]) {
    NSLog(@"%@", [error domain]);
}

The user now selects one of the books, this one I would like to persist, but only this one, all the other books are of no interest to me any more.
The Book Entity does not have/or is part of any relationships. It is just a “single” Entity.

If I pull the “save lever” every Book object will be persisted and I will have to delete everything but my desired one.

How would I get around this challenge, I can’t really seem to find that particular use-case in the Core Data Programming Guide, which sort of also bugs me a bit, am I going against best practice here?

Thanks for any help given.

  • 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-14T07:19:30+00:00Added an answer on May 14, 2026 at 7:19 am

    Yes you are going against best practices. In that use case, if you really do not want to save the objects, keep them in an intermediate format and only create a Core Data object for the one you want to persist. However this seems quite wrong.

    What is the harm in saving the other books? Are the only going to be used once ever?

    Based on the small amount of information you have provided, it seems your approach to the problem needs to be reconsidered.

    Update

    Removing unsaved objects from the context has a very small overhead yes so that is the best solution given the parameters you have. I asked the other questions to see if there was a cleaner overall solution rather than building the objects just to throw them away. Sounds like you have already been down that path though.

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

Sidebar

Ask A Question

Stats

  • Questions 463k
  • Answers 463k
  • 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 After trying everything I could think of, my last hope… May 16, 2026 at 12:50 am
  • Editorial Team
    Editorial Team added an answer The this is a simple javascript (DOM) object, $(this) will… May 16, 2026 at 12:50 am
  • Editorial Team
    Editorial Team added an answer This is not just pertaining to php, this applies to… May 16, 2026 at 12:50 am

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.