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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:28:36+00:00 2026-06-02T06:28:36+00:00

I am very new to the Core Data programming. I have a question to

  • 0

I am very new to the Core Data programming. I have a question to which I hope to get some clarification.

Supposing I have an NSManagedObject called Company, with the following attributes:

  • companyName
  • companyEmail
  • companyPhoneNo
  • companyUserName
  • companyPassword

In this object the companyName attribute is indexed.

So, my question is, how can I make sure that there will be only entry with same companyName, companyEmail, companyPhoneNo, companyUserName and companyPassword?

Do I need to make a request to check if there are any records with the same attribute values or is a simple check with the object id sufficient?

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-06-02T06:28:38+00:00Added an answer on June 2, 2026 at 6:28 am

    Here’s an example may be helps:

    NSError * error;
    NSFetchRequest * fetchRequest = [[NSFetchRequest alloc] init];
    [fetchRequest setEntity:[NSEntityDescription entityForName:NSStringFromClass([self class])
                                        inManagedObjectContext:managedObjectContext]];
    [fetchRequest setFetchLimit:1];
    
    // check whether the entity exists or not
    // set predicate as you want, here just use |companyName| as an example
    [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"companyName == %@", companyName]];
    
    // if get a entity, that means exists, so fetch it.
    if ([managedObjectContext countForFetchRequest:fetchRequest error:&error])
      entity = [[managedObjectContext executeFetchRequest:fetchRequest error:&error] lastObject];
    // if not exists, just insert a new entity
    else entity = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass([self class])
                                                inManagedObjectContext:managedObjectContext];
    [fetchRequest release];
    
    // No matter it is new or not, just update data for |entity|
    entity.companyName = companyName;
    // ...
    
    // save
    if (! [managedObjectContext save:&error])
      NSLog(@"Couldn't save data to %@", NSStringFromClass([self class]));
    

    Tip: countForFetchRequest:error: does not fetch entity actually, it just returns a number of entities that match the predicate you set before.

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

Sidebar

Related Questions

I'm very new to the core data programming. I understand that the entities are
I have a simple iPhone app which accesses some remote data on start-up then
This question is about Core Data. I created a Entity called TV with three
I have an iPhone/iPad app which uses Core Data. In my DB I have
I am new to Core Data and I was wondering if I could get
I am playing about with Core Data and very new to it. This chunk
I am trying to debug a very nefarious problem with some iPhone Core Data
I have a very strange problem with inverse relations in Core Data, and I
I very new to Python, and fairly new to regex. (I have no Perl
Im very new to all coding including jquery. I though this would have been

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.