Appending NSDictionary to other NSDictionary

后端 未结 3 641
有刺的猬
有刺的猬 2021-01-31 00:45

I have one NSDictionary and it loads up UITableView. If a user scrolls more and more, I call API and pull new data. This data is again in the form of a

相关标签:
3条回答
  • 2021-01-31 01:37

    Use NSMutableDictionary addEntriesFromDictionary to add the two dictionaries to a new mutable dictionary. You can then create an NSDictionary from the mutable one, but it's not usually necessary to have a dictionary non-mutable.

    0 讨论(0)
  • 2021-01-31 01:47

    You looking for this guy:

    [NSMutableDictionary addEntriesFromDictionary:]
    

    Make sure your UITableView dictionary is an NSMutableDictionary!

    Check it here

    0 讨论(0)
  • 2021-01-31 01:48

    Is your NSDictionary full of other NSDictionaries? It sounds like you would need an NSMutableArray that you could add NSDictionaries to at the end. Assuming you can control the flow of data coming in and wouldn't run the risk of duplicates in your array, you could certainly append the data.

    NSMutableArray *array = [[NSMutableArray alloc] init];
    arrayCount = [array count]; // check the item count
    [array addObject:dictToAppend];
    

    Without seeing how you are implementing it, I can't provide more detailed code examples. Appending items is easy to do, but know it can only be done with mutable versions of Arrays or Dictionaries. Hope this helps a little.

    0 讨论(0)
提交回复
热议问题