Questions tagged [nsmutabledictionary]

NSMutableDictionary is the mutable version of NSDictionary.

Like NSDictionary (), it is a subclass of NSObject (), that allows you to have a collection of objects, but instead of having them stored in an array retrievable by their index, they are stored as a key-value pair. Each object stored in an NSDictionary can be retrieved by a unique key assigned to it. Keys have to be unique and can be any object as long as they adopt the NSCopying protocol – they are usually an instance of NSString ().

Neither a key nor the object paired with it can be nil, however, you may use NSNull for storing null objects.

If two objects are stored with the same key, the first one is released, and the last one is stored.

When using key-value coding, the key must be a string. When using key-object coding, the key is copied using copyWithZone: and it must conform to the NSCopying protocol. This object is retained, rather than copy.

NSMutableDictionary gives you the ability to modify this set of key-object paired collection without having to empty it and refill it again as a whole set. The following methods are for this purpose:

Adding Entries to a Mutable Dictionary

– setObject:forKey: 
– setValue:forKey: 
– addEntriesFromDictionary: 
– setDictionary:

Removing Entries From a Mutable Dictionary

– removeObjectForKey: 
– removeAllObjects 
– removeObjectsForKeys:

Resources:

1306 questions
8
votes
3 answers

How to remove key from nsmutabledictionary When value of that key is empty or null in ios?

I have created NSMutableDictionary and the values of keys are formed as nsarray. I have removed objects of keys. I have no doubt for this case. But I would like to remove key When value of that key is empty or null as following as the case. { …
Prasad G
  • 6,702
  • 7
  • 42
  • 65
8
votes
3 answers

iOS, NSMutableDictionary

I had a problem in my project where I declared in the header file an NSMutableDictionary property like so: @property (copy, nonatomic) NSMutableDictionary *DataDict ; Now in the implementation file, I go ahead and initialise this dictionary because…
Kalamantina
  • 303
  • 4
  • 10
7
votes
2 answers

"Mutating method sent to immutable object" despite object being NSMutableDictionary

I'm using NSMutableDictionary and hit this error: 'NSInternalInconsistencyException', reason: '-[__NSCFDictionary removeObjectForKey:]: mutating method sent to immutable object' Here's the code: // Turn the JSON strings/data into objects …
oky_sabeni
  • 7,672
  • 15
  • 65
  • 89
7
votes
1 answer

NSMutableDictionary addition and removal KVO

I have a quick question regarding KVO. I understand that for a NSArray if observing additions is desired you can do the following. NSIndexSet* set = [NSIndexSet indexSetWithIndex:[someIndex integerValue]]; [self…
7
votes
4 answers

Copying the contents of an NSMutableDictionary into another NSMutableDictionary?

I have an NSMutableDictionary each element of which is another dictionary. What is the best way I can copy its contents into another NSMutableDictionary? I've tried using: firstDictionary = [NSMutableDictionary…
NSExplorer
  • 11,849
  • 12
  • 49
  • 62
7
votes
4 answers

Filtering array of dictionaries in Swift

I have An Array With Dictionaries example : ( { Email = "kate-bell@mac.com"; Name = "Kate Bell"; Number = "(555) 564-8583"; }, { Email = "d-higgins@mac.com"; Name = "Daniel Higgins"; …
7
votes
2 answers

Assigning nil to an element on NSMutableDictionary in Objective-C removes that element, is that a sanctioned feature or bug?

I have a NSMutableDictionary. NSMutableDictionary * dict = @{ @"0" : @"car", @"1" : @"ball", @"2" : @"plane", } At one point, by error, I was assigning…
Duck
  • 34,902
  • 47
  • 248
  • 470
6
votes
3 answers

Is there NSMutableDictionary literal syntax to remove an element?

There is a literal syntax to add object and change object in an NSMutableDictionary, is there a literal syntax to remove object?
Boon
  • 40,656
  • 60
  • 209
  • 315
6
votes
2 answers

How do I add object to NSMutableDictionary with key?

I have a plist. I want add the elememts from that plist to a mutable dictionary. First I check the user name in the plist, and my current name are same or not. If it is same, then I want to add all value to that dictionary rom plist, and also assign…
user2377290
6
votes
3 answers

What is @[] and @{} in Objective-C?

Possible Duplicate: What are the details of “Objective-C Literals” mentioned in the Xcode 4.4 release notes? I've got question about @[] and @{}. Some code taken from internet: self.searches = [@[] mutableCopy]; self.searchResults = [@{}…
Tomasz Szulc
  • 4,217
  • 4
  • 43
  • 79
6
votes
1 answer

blocks in nsdictionary?

So I'm storing block actions into a nsmutabledictionary and then recalling them when a response comes back on a websocket. This turns async request into a block syntax. Here's the stripped down code: - (void)sendMessage:(NSString*)message…
5
votes
4 answers

Case Insensitive Search in NSMutableDictionary

HI, I have a NSMutableDicitionary contains both lowercase and uppercase keys. So currently i don't know how to find the key in the dictionary irrespective key using objective c.
5
votes
5 answers

Is there a clean way to use pointers (ids) as keys in an NSMutableDictionary?

I'm using NSMutableDictionary to store what is effectively a descriptor for certain classes, because I'd rather not waste the memory of adding the descriptor to every instance of classes, since only a very small subset of 1000s of objects will have…
Charles Randall
  • 6,920
  • 12
  • 33
  • 38
5
votes
2 answers

NSMutableDictionary is adding quotes to keys and values - why?

I'm trying to add some additional key/value pairs to an NSMutableDictionary, using: Tag *tag1 = [results1 objectAtIndex:0]; [resultsDict setObject:[tag1 retrieveTextUpToDepth:1] forKey:@"image_url"]; Tag *tag2 = [results2 objectAtIndex:0];…
TimD
  • 8,014
  • 2
  • 24
  • 34
5
votes
3 answers

What's the best way to store and retrieve multi-dimensional NSMutableArrays?

I'm storing a bunch of data in a .plist file (in the application documents folder), and it's structured like this: Dictionary { "description" = "String Value", "sections" = Array ( Array ( Number, ... …
kbanman
  • 4,223
  • 6
  • 32
  • 40