Pregunta

I'm currently trying to set up an NSMutableDictionary with date objects that when added will be a unique date with an automatically added key.

Example:

object:20-04-2014 withKey:datekey1;
object:21-04-2014 withKey:datekey2;

I want save an NSDate as an object and a key which will be explained below:

For example an NSDate object is added to the dictionary

20-04-2014 //for example

This object needs to be given the key of 'key = total NSMutableDictionary keys +1'

An example of how this should now look within the NSMutableDictionary

withObject:"20-04-2014" forKey:"key1"

When the UIBarButtonItem is pressed again and a different date is selected, for example the following day:

21-04-2014 // new NSDate object to be added as an object to the dictionary..

When giving the 2nd NSDate object a key it should automatically be considered that there is already 1 entry and to give a key value of key=totalkeys+1

The following should now be in NSMutableDictionary

withObject:"20-04-2014" forKey:"key1"
withObject:"21-04-2014" forKey:"key2"

ect ect. The number of entries should have the ability to be unlimited.

How is this done?

Regards.

¿Fue útil?

Solución

In the method invoked when you tap the button:

NSString *k = [NSString stringWithFormat:@"key%d", _dictionary.count+1];
[_dictionary setObject:date forKey:k];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top