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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:04:03+00:00 2026-05-12T15:04:03+00:00

I have a Song Entity and a Tag entity and they have a many

  • 0

I have a “Song” Entity and a “Tag” entity and they have a many to many relationship between them. A Song can have multiple Tags and a Tag can be applied to multiple Songs.

I want to check if a Song has a particular Tag associated with it. If the Song has the Tag associted with it, I want to show a checkmark in the table view.

For a similar logic, in Apple “TaggedLocations” sample code, the following check is made to check for the presence of the relationship.

if ([event.tags containsObject:tag]) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
}   

This may be inefficient if there are a lot of Tags in the database as this will fetch all of them in the memory. Please correct me if I am wrong here.

Is there a more efficient way to check if the Song is associated with a particular Tag instead of checking in Song.Tags?

  • 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-12T15:04:03+00:00Added an answer on May 12, 2026 at 3:04 pm

    It’s actually pretty easy to do, if completely undocumented. You want to create a fetch request with a predicate that has a set operation. If we imagine that your Tag model has a property called tagValue, the predicate you care about is “ANY tags.tagValue == ‘footag'”

    NSString *tagSearch = @"footag";
    
    // However you get your NSManagedObjectContext.  If you use template code, it's from
    // the UIApplicationDelegate
    NSManagedObjectContext *context = [delegate managedObjectContext];
    
    // Is there no shortcut for this?  Maybe not, seems to be per context...
    NSEntityDescription *songEntity = [NSEntityDescription entityForName:@"Song" inManagedObjectContext:context];
    
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:songEntity];
    
    // The request looks for this a group with the supplied name
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY tags.tagValue == %@", tagSearch];
    [request setPredicate:predicate];
    
    NSError *error = nil;
    NSArray *results = [context executeFetchRequest:request error:&error];
    
    [request release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 entities: Song Artist Genre One song can have multiple genres and
I have a table for songs, where each song can have up to 3
I have a class PlaylistTrack that I want to extend class Song. When I
Let's say I have 3 MySQL table. A song db called songs that has
So far I have: $qb1 = $this->getEntityManager()->createQueryBuilder(); $qb1->select('s') ->from('\My\Entity\Song', 's') ->where('s.id <> ?1') ->orderBy('RAND()',
Suppose I have a Song entity and Genre entity in Core Data. Genres have
Have an entity class (Song) with a @OneToMany mapping to another entity (CoverArt), and
I have a song playing app. The songs are loaded into a NSCollectionView. There
I have an Core Data entity called Album; an album has a relationship to
I have a Song model which contains hundreds of thousands of songs, when I

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.