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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:03:35+00:00 2026-05-15T02:03:35+00:00

I have a question about Objective-C today involving NSMutableArray. Coming from a .net/c# background

  • 0

I have a question about Objective-C today involving NSMutableArray. Coming from a .net/c# background I’m having some trouble working with these things.

Let’s say I have an object called "Song"

My song has 3 properties:

  • Title
  • Artist
  • Genre

I have a NSMutableArray or NSArray which holds all my Song objects.

How would I go about trying to ‘query’ my array to get a new array with only (Unique) Artists or Genre’s.

Where as in .net you would write a simple LINQ query with a DISTINCT clause, how would one solve this in Objective-C? I’m guessing with predicates but am struggling to find a solution.

  • 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-15T02:03:36+00:00Added an answer on May 15, 2026 at 2:03 am

    Depending on what you mean by “unique artists,” there are a couple of different solutions. If you just want to get all the artists and don’t want any to appear more than once, just do [NSSet setWithArray:[songArray valueForKey:@"artist"]]. If you mean you want to set a list of all the songs which are the only song by their artist, you need to first find the artists who only do one song and then find the songs by those artists:

    NSCountedSet *artistsWithCounts = [NSCountedSet setWithArray:[songArray valueForKey:@"artist"]];
    NSMutableSet *uniqueArtists = [NSMutableSet set];
    for (id artist in artistsWithCounts)
        if ([artistsWithCounts countForObject:artist] == 1])
            [uniqueArtists addObject:artist];
    NSPredicate *findUniqueArtists = [NSPredicate predicateWithFormat:@"artist IN %@", uniqueArtists];
    NSArray *songsWithUniqueArtists = [songArray filteredArrayUsingPredicate:findUniqueArtists];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Objective-C in my app and I have a question about multiple
I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) The
I have a question about SqlDataReader: Is there some way to modificated the values
I have a question about the arc4random() function in Objective-C. In the examples I
I want to ask a question about the objective C. I have create a
I have a question about the first paramater in Objective-C -(NSInteger) totalSeconds:(NSInteger)h minutes:(NSInteger)m seconds:(NSInteger)s;
I have a question about ARC nad NSMutableArray. Here's the case: I have a
I have a simple question about creating multiple initialisers within an objective-c class. Basically
I have a general question about writing init methods in Objective-C. I see it
I have a question about variable declaration in Objective-C in case of global variable

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.