nsmutabledictionary

Memory leak in NSMutableDictionary, NSArray in NSXMLParser

I'm suffering from a bad memory leak parsing one of my xml documents. I'm using the NSXMLParser to iterate each node (album in the xml sample below), then iterate each photo node and add the result to an NSArray. I have 2 retained properties, which store two values on each loop. These values are added to a NSMutableDictionary object a...

Cocoa: Any downside to using NSSet as key in NSMutableDictionary?

Is there any downside to using NSSet as key in NSMutableDictionary, any gotchas to be aware of, any huge performance hits? I think keys are copied in Cocoa containers, does it mean NSSet is copied to dictionary? Or is there some optimization that retains the NSSet in this case? Related to http://stackoverflow.com/questions/1863061/can-...

How to addObject of NSMutableDictionary to NSMutableArray in a loop

Hi all, I'm having difficulty to add a data structure to an array to create an array of dictionaries from a loop. I just knew that addObject in NSMutableArray only add pointer to it. I would like to know how to achieve my goal. Here's my code: NSMutableDictionary *woRows = [[NSMutableDictionary alloc] init]; NSMutableArray *workOrders...

NSMutableDictionary thread safety

I have a question on thread safety while using NSMutableDictionary Main thread is reading data from NSMutableDictionary where key is Nsstring value is UIImage Async thread is writing data to above dictionary (using NSOperationQueue) how do I make above dictionary thread safe Should I make Property NSMutableDictionary as "Atomic" or ...

How to clear a dictionary?

I'm currently doing the following to clear out an NSMutableDictionary [myDictionary release]; myDictionary = [[NSMutableDictionary alloc] init]; The release line doesn't actually release any objects in the dictionary. I can still see all of them on the next line. It isn't until the alloc line is executed that the dictionary is zeroed...

Best way to handle persistent Boolean in plist?

What's the best way to handle Boolean values that derive from a UISwitch setting, and are stored in an NSMutableDictionary that is saved to the user's directory as persistent settings? Specifically, what's the best way to keep boolean values distinct from numeric values in an NSMutableDictionary that gets written to and read from the fil...

Stuff NSMutableDicitonary into NSMutableArray

I am newbie to Iphone Application development. Please help me. I am sorry if I am wrong. I have following declarations: //.h file: NSMutableArray *dataArray; NSMutableDictionary *item; //.m file - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedN...

How do I add multiple keys and values to an NSMutableDictionary without using an array?

I know you could add all the keys to an array and add it to one side of the dictionary but I'm curious how you can add or insert a value at a certain point in the dictionary. The way i have it now it I believe it just keeps overwriting the last entries to make room for the new one: NSMutableDictionary *bookmarks = [[NSMutableDictionary ...

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, ... Number ), Array ( Number, ... Num...

for each loop in objective c for accessing NSMutable dictionary

I am finding some difficulty in accessing mutable dictionary keys and values in Objective-C. Suppose I have this: NSMutableDictionary *xyz=[[NSMutableDictionary alloc] init]; I can set keys and values. Now, I just want to access each key and value, but I don't know the number of keys set. In PHP it is very easy, something as follows...

Reusable NSMutableDictionary

Someone in that forum proposed me a code solution that worked great, but for my understanding, I would like to know what is the difference between the 2 blocks of code: Block 1 NSMutableDictionary* step_info = [NSMutableDictionary dictionary]; Block 2 NSMutableDictionary* step_info = nil; step_info = [NSMutableDictionary dictionary]...

NSMutableDictionary sometimes shows value or key with quotes

I am parsing a data file and adding the key-value read from the file into an NSMutableDictionary. I have noticed that when I print out the content of the dictionary in the debugger, i.e: po myDictionary some entries have quotes around them and some don't. Why is this? For instance I see: { "file_path" = "../dat.txt" anot...

How to add the value of string into hashtable in iPhone coding?

for(NSString *s in mainarr) { NSString newseparator = @"="; NSArray *subarray = [s componentsSeparatedByString : newseparator]; //Copying the elements of array into key and object string variables NSString *key = [subarray objectAtIndex:0]; NSLog(@"%@",key); NSString *class_name= [subarray objectAtIndex:1]; ...

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 ? Thanks in advance ...

NSMutableDictionary removeObjectForKey throwing EXC_BAD_ACCESS for a var that isn't released...

I have a plist. It has several dozen keys, each with NSMutableArray items: ... <key>KeyName1</key> <array> <string>String1</string> <string>String2</string> <string>String3</string> </array> <key>KeyName2</key> <array> <string>String1</string> <string>String2</string> <string>String3</string> </array> ... I ha...

How to get the value for each key in dictionary in Objective-C?

Hello, I'm maintaining a NSMutableDictionary which holds key and value pair.Now i need to perform some operation for each value in it.How to retrive value from dictionary. // this is NSMutableDIctionary NSMutableDictionary *dictobj = [[NSMutableDictionary alloc]init]; // in methodA -(void)methodA { //get the value for each key and...

No key/value pairs being saved in NSMutableDictionary

When my app starts, it loops through adding values of random numbers with keys of co-ordinates on a grid to a dictionary. Here is a bit of the code: [grid setObject:v forKey:k]; K is a string in form "xy" where x and y are single digit integers and V is an NSNumber. Both of these are logged to the console before adding so I know these...

Memory problems with NSMutableDictionary, causing NSCFDictionary memory leaks

Hi! Help me please with the following problem: - (NSDictionary *)getGamesList { NSMutableDictionary *gamesDictionary = [[NSMutableDictionary dictionary] retain]; // I was trying to change this on the commented code below, but did have no effect // NSMutableDictionary *gamesDictionary = [[NSMutableDictionary alloc] init]; // [g...

Cocoa's NSDictionary: why are keys copied?

All objects used as keys in NS(Mutable)Dictionaries must support the NSCopying protocol, and those objects are copied when they're used in the dictionary. I frequently want to use heavier weight objects as keys, simply to map one object to another. What I really mean when I do that is effectively: [dictionary setObject:someObject forKe...

"-[CFNumber intValue]: message sent to deallocated instance" and no idea

Hey there, i have a problem with a exc bad access. I already turned in NSZombieEnabled, but cannot figure out why this problem will be caused. How the cartInstance Array is defined you can see below in the following function. It's a NSMutableArray with several NSMutableDictionaries The error occurs every time my counter i reaches 13. The...