I load from a txt file many info, and I would like, if possible, to dynamically create NSmutable dictionary with the elements of the txt.
For example, each is like that:
id of element | date | text
What I'm asking is the equivalent of the NSString stringWithFormat:.
Can we do the same for an Mutable Dictionary?
To be more practical, let's say the NSString *date is equal to "23/12/2009" (for europe). I want to create a dictionary called 23/12/2009 without declaring *23/12/2009 but just something like dictionaryWithFormat: @"%@", date];
I'm stuck on this, and I don't even know if it is possible. If not, what's the best way to approach that?
you can download from web an xml with your informations.
So that you can parse it and update your arrays that represent the name of the cell and the other things.
***
Thank you. Can you send me a sample script of how to do that? I need to replace the "Revolution in Libya" name with a link to the XML file.
[topArea addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:
@"Revolution in Libya",@"name",
@"hottopic.png",@"picture",
@"http://www.WHERE THE LINK FILE IS LOCATED",@"url",nil]];
first thing you don't need a "script" because objective-c is not a scripting language.
however i have no ready code for you.
google NSURLConnection or ASIHTTPRequest to understand how you can download a file xml, then google NSXMLParser to understand how you can parse a file xml.......then should be trivial to create objects dinamically.
I load from a txt file many info, and I would like, if possible, to dynamically create NSmutable dictionary with the elements of the txt.
For example, each is like that:
id of element | date | text
What I'm asking is the equivalent of the NSString stringWithFormat:.
Can we do the same for an Mutable Dictionary?
To be more practical, let's say the NSString *date is equal to "23/12/2009" (for europe). I want to create a dictionary called 23/12/2009 without declaring *23/12/2009 but just something like dictionaryWithFormat: @"%@", date];
I'm stuck on this, and I don't even know if it is possible. If not, what's the best way to approach that?
Thanks everyone
Regards
Sounds to me like you should use a single dictionary to store all of your records.
A dictionary stores key/value pairs. The key is almost always a string. The value is any object.
So you could use either the date or the id of the item as the key, and save the data as the value.
I don't quite understand what you're trying to do, though.
Don't describe creating a dictionary, because I think you misunderstand how to use dictionaries. Instead, describe the type of information you want to store, and how you want to retrieve it. e.g. I want to create a database of records using an ID number as a key. Each record would contain a date and a text string.
If you want to be able to look up these records using multiple keys the problem is more complicated. (If you want to be able to find items by ID number or by date, for example). In that case you might want to create an SQL database.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.