nsdictionary

Help with Points between rounds in objective-c

I am new to objective-c and am having trouble figuring out a way to store points for multiple players in my game. I have 4 characters in my game that are all objects from the same class. 1 is controlled by the user and the other 3 are controlled by the computer. Each level in my game consists of 3 races. I need a way to keep track of eac...

NSDictionary into 1 NSMutableArray

Hi Is it possible to take 2 NSDictionaries and populate 1 NSMutableArray? So lets say I have this situation: dict1 = key/value of: id/firstname dict2 = key/value of: id/lastname (These are populated from a database query to the server) Now, I want to combine the dictionaries into an NSMutableArray of "user" objects. the user object ...

NSDictionary WriteToFile fails

I can't work out why it keeps failing. It returns NO. I have searched this all afternoon, but nothing explains why or how to fix. Calling [[NSFileManager defaultManager] isWritableFileAtPath:] returns NO, which leads me to believe that the existing plist file can not be overwritten, but I can't work out how to change this. ...

Change objects in NSUserDefaults without creating and re-setting copies

I've got dictionary stored in NSUserDefaults and I need to add/remove items in this dictionary. It bothers me that to do this I have to create mutable copy of entire dictionary, change one element and replace entire dictionary with new copy. copy = [[defaults objectForKey:@"foo"] mutableCopy]; [copy setObject:… forKey:@"bar"]; [default...

NSDictionary From NSMutableData

I was previously using initWithContentsOfURL to download a plist into an NSDictionary, but this hangs the UI when run on the same thread so now I have moved to NSURLConnection the issue is that I can no longer call a method to init the NSDictionary with NSMutableData. What is the best way to take NSMutableData and place it into an NSDict...

Are keys and values in an NSDictionary ordered?

I mean: Is the order of keys and values in an NSDictionary always the same like how they were specified when initializing the NSDictionary? Or should I better maintain a seperate NSArray if I really need to know the order of keys? ...

[Objective C] Leaks hunting

I'm still working on my leaks problem and I don't know how to solve this one I have leaks on each arrayTmp addObject lines NSMutableArray *arrayTmp= [[NSMutableArray alloc] init]; [arrayTmp addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"1", @"value", @"Value 1", @"name", nil]]; [arrayTmp addObject:[NSDictionary dictionaryWithO...

How to add a CGImageRef to a NSDictionary?

I have a CGImageRef variable and a CGRect (so no pointers) and I need to add it to an NSDictionary. Like an NSArray, NSDictionary-s only accept pointers. How can you add an CGImageRef or an CGRect anyway? ...

Plist Array to NSDictionary

I have a plist: <plist version="1.0"> <array> <dict> <key>name</key> <string>Alabama</string> <key>abreviation</key> <string>AL</string> <key>date</key> <string>1819</string> <key>population</key> <string>4,627,851</string> <key>capital</key> <string>Montgomery</string> ...

Why don't the Children in my dictionary fill up ...

Hello all I'm using NSXMLParser to parse some xml data. I'm using this data to build a Tree representation to create a hierarchy for a drilldowntable. - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary...

Add 2d int array to NSDictionary

Hello - I am new to Objective C and am having troubles adding a 2d int array to a NSMutableDictionary. The code errors with "incompatible pointer type" - I assume this is because setObject would be expecting an object.. Here is the code - I am trying to have a Dictionary containing my level data: NSMutableDictionary *level = [[NSMutabl...

NSDictionary. How do I create directly from aformated file?

This is a fairly trivial data parsing question. I'm just unclear on the methods I should be using to pull it off. I've got a plain text file of a few hundred lines. Each line is of exactly the same format. The lines are in contiguous chunks where the first item in a line is essentially a key that is repeated for each line in a chunk: k...

Convert NSArray to NSDictionary

How can I convert an NSArray to an NSDictionary, using an int field of the array's objects as key for the NSDictionary? ...

How do I pull an integer out of a NSDictionary and put it in an integer?

I've got an NSDictionary that was initialized with a plist that, among other things, contained count followed by 32 and I want to get at the value for count. How? I know how to get it into an object via [dictionaryObjectName objectForKey:@"count"] But to me, the value I'm obtaining is not an object. If I have to specify an object,...

NSManagedObject as NSDictionary key?

In my app, I have a NSDictionary whose keys should be instances of a subclass of NSManagedObject. The problem, however, is that NSManagedObject does not implement the NSCopying protocol which means that no Core Data objects / instances of NSManagedObject can be used as dictionary keys even though the -[hash] method works fine for them....

Take some object in NSArray and put it randomly in labels

I choose index of an array from a plist. It's a dictionary with 10 different line with string. NSArray* tableau = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"codes" ofType:@"plist"]]; NSDictionary* phrase = [tableau objectAtIndex:nombreChoisi]; I would like to take 6 elements and put them in 6 labels...

Using valueForKeyPath on NSDictionary if a key starts the @ symbol?

Hi there, I want to use valueForKeyPath on my NSDictionary, but the problem is that one of the keys is a string that starts with the @ symbol. I have no control over the naming of the key. I'm having problems trying to create the key path as I'm getting a format exception, even when trying to escape the @ symbol: This works fine: [[[...

valueForKey only returns memory address and not actually value

NSDictionary *topic = [spaces objectAtIndex:i]; NSInteger topicid = [topic valueForKey:@"TOPICID"]; when I run this and print out topic I get the following: Printing description of topic: <CFDictionary 0xdb2a70 [0x30307a00]>{type = mutable, count = 2, capacity = 12, pairs = ( 10 : <CFString 0xdb5300 [0x30307a00]>{contents = "TOP...

Mapping integers to booleans in Objective-C

In Objective-C I need to associate a mutable collection integers (monotonic, non-contiguous, could get fairly large) to boolean values. The obvious way is just to have an NSDictionary w/ NSNumbers as keys and values. Is there a better way that doesn't involve so much object creation? I'm really not trying to pre-optimize so much as lea...

Cocoa and Cocoa Touch: is an object on the dictionary?

I thought it would be simpler to find if an object in on a dictionary, but it appears it is not. I have a NSMutableDictionary with just one key named "products". I have several products added to the dictionary dynamically, using something like [myDict addObject:@"banana" forKey:@"products"]; [myDict addObject:@"orange" forKey:@"produc...