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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:26:08+00:00 2026-06-10T23:26:08+00:00

There is this hard problem I got to solve, and I’m banging my head

  • 0

There is this hard problem I got to solve, and I’m banging my head for the past couple of days. So I have 2 arrays.

Here is the first one:

 {
        categories =         (
                        {
                id = "user/06617213952393255174/label/Main Folder";
                label = "Main Folder";
            }
        );
        firstitemmsec = 1297785485208;
        htmlUrl = "http://awebslife.tumblr.com/";
        id = "feed/http://awebslife.tumblr.com/rss";
        sortid = D5DB1FE2;
        title = "awebslife.tumblr.com/rss";
    },
        {
        categories =         (
                        {
                id = "user/06617213952393255174/label/Main Folder";
                label = "Main Folder";
            }
        );
        firstitemmsec = 1344454207448;
        htmlUrl = "http://awholelotofnothing.net";
        id = "feed/http://awholelotofnothing.net/feed/";
        sortid = 7098B8F7;
        title = "awholelotofnothing.net/feed/";
    },

As you can see 2 objects, dictionaries. In my real app they are much more objects, but this is just an example.
The other array:

    {
    count = 4;
    id = "feed/http://awebslife.tumblr.com/rss";
    newestItemTimestampUsec = 1346087733278957;
     },

So here is the actual problem. I’m trying to match the second array with the first and combine them, but as you can see the second array only have objects which count is > 0. In my case in the first array my second object’s count is 0. So if I match them, after combining to one array, I am left with only one object, while the other one i can’t figure out how to put something like count = 0 for it. Here is how I match them:

-(void)gotUnreadCount:(NSDictionary *)unreadCount
{
    NSMutableArray *mutableArr = [NSMutableArray array];

    for (NSDictionary *unreadCountDict in unreadCount) {
        for (NSDictionary *feedDict in self.subcriptionsNC) {
            NSMutableDictionary *feedDictMutable = [feedDict mutableCopy];
            if ([[unreadCountDict objectForKey:@"id"] isEqualToString:[feedDict objectForKey:@"id"]]) {

                [feedDictMutable setObject:[unreadCountDict objectForKey:@"count"] forKey:@"count"];
                [mutableArr addObject:feedDictMutable];
            }
        }
    }
}

self.subscriptionsNC is the first array, unreadCount is the second.

I am left with the first object from self.subscriptionsNC, which count is > 0. The other which count is equal to 0 is not added to my combined array, because it’s not present in the second array. (which is just overwriting self.subscriptionsNC)

I want if an item from the first array have no count (note: count is not specified nowhere, except from the second array, which doesn’t show count equal to 0) to assign a count of 0.

Thank you!

  • 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-10T23:26:10+00:00Added an answer on June 10, 2026 at 11:26 pm

    While you check to see if you have a match for IDs between the two arrays, you don’t ever handle the mismatch scenarios. Although in that case, it gets tricky to do with your loop as you have to constantly check that you haven’t already added that item before, and so on. Hope that makes sense, it’s late here 🙂

    Here is some code that seemed to solve the problem with data from your example set:

    NSDictionary *firstNoCount = @{@"id" : @"feed/http://awebslife.tumblr.com/rss"};
    NSDictionary *firstWithCount = @{ @"id" : @"feed/http://awebslife.tumblr.com/rss", @"count" : @4 };
    NSDictionary *secondNoCount = @{ @"id" : @"feed/http://awholelotofnothing.net/feed/" };
    NSArray *subscriptionsWithoutCount = @[ firstNoCount, secondNoCount ];
    NSArray *subscriptionsWithUnreadCount = @[ firstWithCount ];
    NSArray *allIds = [subscriptionsWithoutCount valueForKey:@"id"];
    NSArray *idsWithUnreadCount = [subscriptionsWithUnreadCount valueForKey:@"id"];
    
    NSIndexSet *indexesWithZeroCount = [allIds indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
        return ![idsWithUnreadCount containsObject:obj];
    }];
    
    NSMutableArray *combined = [NSMutableArray array];
    
    [subscriptionsWithoutCount enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        NSMutableDictionary *mutableItemDictionary = [(NSDictionary *)obj mutableCopy];
        NSNumber *unreadCountNumber = nil;
        if ([indexesWithZeroCount containsIndex:idx])
        {
            unreadCountNumber = @0;
        }
        else
        {
            NSInteger indexInCountArray = [idsWithUnreadCount indexOfObject:[mutableItemDictionary objectForKey:@"id"]];
            NSDictionary *countDictionary = [subscriptionsWithUnreadCount objectAtIndex:indexInCountArray];
            unreadCountNumber = [countDictionary objectForKey:@"count"];
        }
        [mutableItemDictionary setObject:unreadCountNumber forKey:@"count"];
        [combined addObject:mutableItemDictionary];
    }];
    
    NSLog(@"combined = %@",combined);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

there's this interesting problem i can not solve myself. I will be very glad,
Here's a recurring problem. There are similar questions on SO about this, but nothing
there is this check-in-out program here at my workplace, it only takes the data
There was this problem that has been asked about implementing a load byte into
I've got a wonderfully fun little SQL problem to solve today and thought I'd
I have tried to ask a variant of this question before. I got some
Hey there! Here is my setting : I've got a c# application that extracts
Got a problem that I'm having a hard time getting started on. Not a
This problem is a little hard to explain. I'll do my best, hoping to
Before I start, yes this is a homework. I would not have posted here

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.