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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:40:24+00:00 2026-06-04T20:40:24+00:00

In my CoreData data model, there is a Note entity, and a Tag entity,

  • 0

In my CoreData data model, there is a Note entity, and a Tag entity, they have many to many relationships, so each Note can have many Tags, and each Tag may belong to many Notes.

The tags are entered as strings separated by comma:
cat, dog, pig

then I split the string to ‘cat’, ‘dog’, ‘pig’

suppose if I have a Note with tags ‘cat’, ‘dog’, ‘pig’, and I removed ‘pig’ and added ‘bird’, at first I have a string:
“cat, dog, bird” then ‘cat’, ‘dog’, ‘bird’,

Now what should I do? Should I remove all tags for this Note and re-add all the tags? But once I removed all the tags, do other Notes that share the same tag lose those tags?

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-04T20:40:25+00:00Added an answer on June 4, 2026 at 8:40 pm

    You’re confusing deleting an object with removing it from a relationship.

    Firstly, check the delete rule on your relationship:

    delete rule

    If the delete rule is “nullify”, then that means that you can remove objects from the relationship without deleting the object. That sounds like what you want in this case: you want to be able to remove a tag from a relationship with a specific note without affecting all other notes that use the tag.

    Regarding actually amending the relationship with your new set of tags, there are two things you could do. The first way is as you mentioned, to just remove all the tags from the note and re-add them. That’s quite a good plan actually. When you’re adding the tags, of course, for each tag you need to check if it exists first, and if it does, add the existing tag to the relationship.

    In pseudocode:

    1. Remove all the tags from your current note.
    2. Make a mutable set, to hold the ones you want to add.
    3. Get your new array of strings for the linked tags
    4. For each tag string, do the following:
      1. Create a predicate to find a Tag object with that name. Create a fetch request, and execute it.
      2. Look at the result: if there is a returned tag (i.e. the result array has >0 objects in it), add that to your mutable set.
      3. If there was no returned tag (i.e. there is no tag with that name), create a new Tag object. Add that to your mutable set.
    5. Set your Note’s tags property to your new set of tags.

    The alternative way to do it, which lets you add and remove tags one at a time from the relationship, is to call NSMutableSet *mySet = [yourNote mutableSetValueForKey:@"tags"]. That returns you a mutable set of tag objects, and any changes you make to the set are automatically seen by Core Data. So you can remove an object from it, and then that object will no longer be in the relationship, or you can add another tag to the set, and it’ll become related to the note.

    At no time in any of this did we delete an object from the database. All your tags still exist, we just changed which ones are related to which notes.

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

Sidebar

Related Questions

I have a one-to-many relationship in my core data model. There can be many
Here's an example of my data model: There are mailboxes Each mailbox has many
I have this Core Data Model Hierarchy, with the respective relationships to each other:
I have a Core Data model setup like so: Blockbuster Entity To-Many relationship to
I have core data model with two entities that have a many-to-many relationship with
In my core data model I have a Person entity that has a to
I have an entity in my core data model like this: @interface Selection :
We have an app with highly interrelated data, i.e. there are many cases where
I have a Core Data model entity NoteObject that has a transformable type arrayOfTags
I have a core data model with an entity called clients that is made

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.