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
12
votes
3 answers

Subclassing NSMutableDictionary

I am trying to implement a subclass of NSMutableDictionary that returns nil instead of throwing a NSUndefinedKeyException when the key is not present in the Dictionary. However when I try to add objects to my dictionary I get [NSMutableDictionary…
Ben
  • 532
  • 2
  • 4
  • 12
12
votes
5 answers

Swift Dictionary [String:String] to NSMutableDictionary?

I am trying to create and assign a Swift Dictionary of type [String : String] at the SKSpriteNode property userData which requires an NSMutableDictionary. When I try this I get the error: '[String : String]' is not convertible to…
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
11
votes
3 answers

how can I sort NSMutableDictionary with keys value?

I have a NSMutableDictionary with string keys and every key has its own array. I want to re-sort the dictionary with keys value alphabetically. How can I do this?
Alaattin Bedir
  • 193
  • 2
  • 3
  • 10
11
votes
2 answers

Spritekit crashes when entering background

Allright guys, I've been developing an app in which I have a NSMutableDictionary with an SKAction object in it. The SKAction is for playing a sound. This all works well, except ... the app crashes upon entering background with the following stack…
Sabatino
  • 379
  • 4
  • 11
10
votes
5 answers

How can i get Original order of NSDictionary/NSMutableDictionary?

i have created NSMutableDictionary with 10 keys.Now i want to access NSMutableDictionary keys in a same order as it was added to NSMutableDictionary (using SetValue:* forKey:* ); How can i achieve that ?
Matrix
  • 7,477
  • 14
  • 66
  • 97
10
votes
4 answers

NSMutableDictionary with UIButton* as keys - iPhone development

I'm new to iPhone development and I have a question that may have a very simple answer. I am trying to add buttons to a view and these buttons are associated with a custom class that I defined. When I add the buttons to the view, I would like to…
Alejandro A.
  • 101
  • 1
  • 3
10
votes
4 answers

Creating nested JSON string using nsmutabledictionary

I'm trying to create a json string of the below format: { "cat_id" : 4992, "brand" : "Toshiba", "weight" : { "gte":1000000, "lt":1500000 }, "sitedetails" : { "name" : "newegg.com", "latestoffers" : { "currency":…
Siddharthan Asokan
  • 4,321
  • 11
  • 44
  • 80
10
votes
2 answers

NSDictionary setValue:

OK, this is driving me nuts -- please tell me I'm not losing my mind! I declare: NSMutableDictionary* generalSettingsDict; im my .h I init: generalSettingsDict = [[NSMutableDictionary alloc] initWithCapacity:5]; in a viewWillAppear I…
9
votes
6 answers

How do I use the writeToFile method on an NSMutableDictionary?

I would like to use a method (writeToFile) only available for NSDictionary to a NSMutableDictionary object. So, how do I convert this NSMutableDictionary object to NSDictionary?
Stephane
  • 4,978
  • 9
  • 51
  • 86
9
votes
3 answers

cast from [String:AnyObject] to unrelated type NSMutableDictionary always fails Warning

Code is working, but how do I silent this warning that keeps on appearing every time? let parentView = self.parentViewController as! SBProfileViewController parentView.savedDetailsModel =…
Jitendra
  • 842
  • 1
  • 9
  • 25
9
votes
4 answers

NSMutableDictionary with single key holding many values in Objective-C programming

Please tell me how can we have multiple values for the same key in NSMutableDictionary? When I use the below approach, the values are being replaced with the recent one. In my case: [dictionary setObject:forename forKey:[NSNumber…
suse
  • 10,503
  • 23
  • 79
  • 113
9
votes
3 answers

How to update NSMutableDictionary?

I have an NSMutableDictionary. NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; I have to update an element in that dictionary. How i can do that?
S.P.
  • 5,427
  • 11
  • 56
  • 83
9
votes
3 answers

Issues using NSIndexPath as key in NSMutableDictionary?

Is there any particular reason why attempting to store and retrieve a value in an NSMutableDictionary using an NSIndexPath as a key might fail? I originally attempted to do this in order to store an NSMutableDictionary of UITableViewCell heights…
9
votes
5 answers

How to swap `NSMutableDictionary` key and values in place?

I have a NSMutableDictionary and I want to swap values & keys. i.e, after swapping values becomes keys and its corresponding keys with become values All keys and values are unique. Looking for an in place solution because size is very big . Also,…
Kunal Balani
  • 4,739
  • 4
  • 36
  • 73
8
votes
5 answers

How do you store "int" values in an NSMutableArray* or NSMutableDictionary*? Chronic problems with JSON data that come in as integers.

How do you store "int" values in an NSMutableArray or NSMutableDictionary? Chronic problems with JSON data that come in as integers. Should I try to store these integers as NSNumber objects or just as strings that contain the integer? How…
MikeN
  • 45,039
  • 49
  • 151
  • 227
1 2
3
87 88