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
5
votes
1 answer

What is the relationship between elements of plists, arrays and dictionaries?

I've got a simple program that needs to log and persistently store 2 simple pieces of data produced each time the user selects an item in a table view. The two pieces of data are 1) the time of the tap (NSDate) and 2) the name of the item tapped…
rattletrap99
  • 1,469
  • 2
  • 17
  • 36
5
votes
1 answer

Access object of Nested NSDictionary

Is there a way to directly access an inner-Dictionary of an outer Dictionary in Objective-C? For example, I have key to an object which is part of inner dictionary, Is there any way to directly access object from that key. GameDictionary { …
Mayur
  • 81
  • 1
  • 5
5
votes
2 answers

NSMutableDictionary Adding multiple objects to one key

How do I add multiple objects to same key in an NSMutableDictionary? I cannot find the right method. The setObject method only updates a single object in the key array. The method addObject: forkey: in the NSMutableDictionary isn't available and is…
Johan Sneek
  • 49
  • 1
  • 6
5
votes
1 answer

CFPropertyListCreateDeepCopy fails to process array / dictionary containing NSNull

For some reason this sample code works: NSArray *immutable = @[ @"a", @"b", @"c" ]; NSMutableArray *mutable = (__bridge id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFArrayRef)immutable, kCFPropertyListMutableContainers); and…
5
votes
1 answer

nsdictionary copy vs mutable copy

I have NSMutableDictionary *myDictionary = [[NSMutableDictionary alloc] init]; id dict = [myDictionary copy]; but is dict now just a regular NSDictionary? Or is it a copy of the NSMutableDictionary? Also, is there any way to go from mutable to…
Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
4
votes
3 answers

Searching for a value in an unknown NSMutableArray depth

Ok, i kind of asked the wrong question so I've edited the original question. I'm storing Arrays within Arrays, as well as NSDictionaries. It's a utility kind of application and there is no set structure, the user can enter nested information as much…
user1168056
  • 401
  • 8
  • 19
4
votes
2 answers

Why NSMutableDictionary don't want write to file?

- (void)viewDidLoad { [super viewDidLoad]; if ([[NSFileManager defaultManager] fileExistsAtPath:pathString]) { infoDict = [[NSMutableDictionary alloc] initWithContentsOfFile:pathString]; } else { infoDict =…
Igor Bidiniuc
  • 1,540
  • 1
  • 16
  • 27
4
votes
2 answers

Save MPMediaItem into a NSMutableDictionary

I am trying to save the MPMediaItem in nsmutableDictionary.. Actually my purpose is to let the user select his songs and then have it saved in the app and then whenever he wants he can play. i have added this code for saving the MPMediaItem to…
Darshan
  • 121
  • 1
  • 2
  • 10
4
votes
2 answers

How to add the object array to nsmutabledictionary with another array as key

for(Attribute* attribute in appDelegate.attributeArray) { attribute = [appDelegate.attributeArray objectAtIndex:z]; attri = attribute.zName; int y = 0; for(Row* r in appDelegate.elementsArray) { r = [appDelegate.elementsArray…
Bala
  • 136
  • 1
  • 1
  • 14
4
votes
2 answers

Objective-C: Getting Value from NSMutableDictionary with custom object key

I've always used NSDictionaries with strings as keys, and pretty much all the examples on the web/books/etc. are the same. I figured that I'd try it with a custom object for a key. I've read up on implementing the "copyWithZone" method and created…
5StringRyan
  • 3,604
  • 5
  • 46
  • 69
4
votes
4 answers

How to copy NSMutableDictionary values into the another NSMutableDictionary in iPhone?

I want to copy a NSMUtableDictionary values into the another NSMutableDictioary. How can i do that? Here my code is, PersonClass.h file: NSMutableDictionary *tempDictionary; @property (nonatomic, retain) NSMutableDictionary *tempDictionary; …
Pugalmuni
  • 9,350
  • 8
  • 56
  • 97
4
votes
1 answer

'NSInvalidArgumentException '-[NSTaggedPointerString count]: unrecognized selector sent to instance 0xa006162696a614e6'

I am a newbie and designing a weather forecast app as my first project in iOS. I have designed a UISearchBar for searching the cities name. The search bar is working as: 1) Step 1: Type "Naji". It is showing two cities in table view: Naji Naji 2)…
4
votes
0 answers

SpriteKit SKNode User Data returning nil

I am using the userData of an SKSpriteNode to save custom data into it. I have initialized the userData with value through this line of code: oscIcon.userData = NSMutableDictionary() oscIcon.userData?.setValue("0.01",forKey: "rValue") print("init…
4
votes
1 answer

How to check if the value in an NSDictionary exists in an array of dictionarys

The title is a bit confusing...I'll explain I have an NSMutableArray I am populating with NSMutableDictionary objects. What I am trying to do is before the dictionary object is added to the array, I need to check whether any of the dictionaries…
rson
  • 1,455
  • 2
  • 24
  • 43
4
votes
1 answer

How to change a value inside a dictionary in an array that's inside a dictionary?

I have a plist dictionary with several arrays where each have different number of items. These items are dictionaries too. So basically it looks like this: Root dictionary names array places array Item 0 dictionary Item 1 dictionary placeName…
elcool
  • 6,041
  • 7
  • 29
  • 44