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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:46:12+00:00 2026-06-03T00:46:12+00:00

I have a NSSet method checking for duplicates and the count of duplicates of

  • 0

I have a NSSet method checking for duplicates and the count of duplicates of each name. I want to place the names in the table view with the number of duplicates with it. I have taken 100 names and return 27 cells after I find duplicates but I can not seem to get the number of duplicates to be placed in the table view with the corresponding names. Here is a screen shot and method I have been trying to work with to get this working.

enter image description here

- (NSSet *)checkForDuplicateIDs {

//CHECK FOR DUPLICATES IN ARRAY
NSArray *allIDs = [tweetArray valueForKeyPath:@"sender_screen_name"];
NSArray *sortedIDs = [allIDs sortedArrayUsingSelector:@selector(compare:)];

NSString *previousID = nil;
duplicateIDs = [NSMutableSet set];
for (NSString *anID in sortedIDs) {
    if ([previousID isEqualToString:anID]) {
        [duplicateIDs addObject:anID];

    }
    previousID = anID;
}


//THEN REMOVE ANY DUPLICATES IN NEW ARRAY
NSCountedSet *countedSet = [NSCountedSet setWithArray:sortedIDs];
NSMutableArray *oneMess = [NSMutableArray arrayWithCapacity:[sortedIDs count]];
NSMutableArray *multipleMess = [NSMutableArray arrayWithCapacity:[sortedIDs count]];


for(id obj in countedSet) {
    if([countedSet countForObject:obj] == 1) {
        [oneMess addObject:obj];
    }
    for(id duplicatenames in countedSet) {
        if ([countedSet countForObject:duplicatenames]>1) {
            [multipleMess addObject:duplicatenames];
            [countedSet  countForObject:duplicatenames];

        }


    }


}


//other method.... much easier and cleaner but how do I put them into an array?
NSCountedSet *set = [[NSCountedSet alloc] initWithArray:allIDs];

for (id item in set)
{
  //  NSLog(@"Name=%@, Count=%lu", item, (unsigned long)[set countForObject:item]);
}    





//  NSLog(@"NSCountedSet ALL Objects = %@",[countedSet allObjects]);
//  NSLog(@"NSCountedSet = %@",countedSet);

[tweetArray removeAllObjects];
[tweetArray addObjectsFromArray:[countedSet allObjects]];
tweetArrayCount = [[NSMutableArray alloc] initWithObjects:countedSet, nil];


//NSLog(@"One Message = %@",oneMess);
// NSLog(@"Multiple Messages = %@",multipleMess);


//HERE I HAVE ORIGINAL ARRAY IN ALBETICAL ORDER
// NSLog(@"Messages Containing more then 1 = %@",sortedIDs);    

//HERE I HAVE DUPLICATES IN ALBETICAL ORDER
// NSLog(@"Messages Containing more then 1 = %@",duplicateIDs);

//HERE I HAVE THE MESSAGES ONLY CONTAING 1
//NSLog(@"Messages Containing only 1 = %@",oneMess);


//NSLog(@"Duplicates count = %i",[duplicateIDs count]);
// NSLog(@"Messages Containing only count = %i",[oneMess count]);



[mainTableView reloadData];


return [[duplicateIDs copy] autorelease];

}
  • 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-03T00:46:14+00:00Added an answer on June 3, 2026 at 12:46 am

    I modified a simple UITableView example that lists country names to do what I think you want to do. The count is put in the detailTextLabel.text.

    countedList = [[NSCountedSet alloc] initWithArray:listOfItems];//listOfItems is an array of country name strings with duplicates
        listOfItems2 = [NSMutableArray array]; // array without duplicates that's the data source for the UITableView
    
        for (NSString *aCountry in countedList) {
            NSMutableDictionary *dict = [NSMutableDictionary dictionary];
            [dict setValue:aCountry forKey:@"name"];
            [dict setValue:[NSString stringWithFormat:@"%lu",[countedList countForObject:aCountry]] forKey:@"count"];
            [listOfItems2 addObject:dict];
        }
    

    And then I used the following method to supply the data for the table:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; //
        }
    
        // Set up the cell...
        cell.textLabel.text = [[listOfItems2 objectAtIndex:indexPath.row]valueForKey:@"name"];
        cell.detailTextLabel.text = [[listOfItems2 objectAtIndex:indexPath.row]valueForKey:@"count"];
        return cell;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an app in which I want to use the touchbegan method.
I have a method such as this: -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ //Use to animate
I have a table list of promotions held in an NSSet which I load
I have a method in my ViewController that adds an image view. The image
I have an UITableViewController to manage an table view which created with subclassed prototype
i have an nsset of room attributes(NSString), i stored them in CoreData. how can
i have this method Code: - (void)addImageSubViewAtX:(CGFloat)x atY:(CGFloat)y { CGRect myImageRect1 = CGRectMake(x, y,
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@ touches ); } The above method is
I have 3 UIViews, layered on top of one large uiview. I want to
I have a Core Data store which contains a number of MediaItem entities that

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.