nsmutabledictionary

Reading plist into TableView

岁酱吖の 提交于 2019-12-03 10:16:13
I started this project with a simple plist of a dictionary with two arrays of strings. I now want to add more information and want to use this plist structure: Root - Dictionary - (2 items) Standard - Array - (3 items) Item 0 - Dictionary - (4 items) Color - String - Red Rvalue - String - 255 Gvalue - String - 0 Bvalue - String - 0 Sorry about typing in the plist but the site would not let me post an image I know that the RGB values could be numbers instead of strings but I have a reason for them being strings. This is the code I used to read the simple plist: - (UITableViewCell *)tableView:

What's the best way to store and retrieve multi-dimensional NSMutableArrays?

﹥>﹥吖頭↗ 提交于 2019-12-03 08:06:59
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, ... Number ) ), "items" = Array ( Array ( Number, ... Number ), Array ( Number, ... Number ) ) } If I just retrieve it with NSMutableDictionary *d = [[NSMutableDictionary alloc] initWithContentsOfFile:plistFile] I won't be able to replace the number objects, correct? So I'm recursing through the data right now and forming a mutable version of the whole thing, and it

Is there a literal syntax for mutable collections?

*爱你&永不变心* 提交于 2019-12-03 08:04:25
问题 I know I can create an NSArray with @[@"foo", @"bar"] or an NSDictionary with @{@0 : @"foo", @1 : @"bar"} . Is there a literal syntax for creating an NSMutableArray or an NSMutableDictionary ? 回答1: No. Just as how there isn't a syntax for creating an NSMutableString either. Mutable objects are not particularly suited to literal values. 回答2: There isn't a built in way, but I just usually use mutableCopy like this: NSMutableArray *array = [@[ @"1", @"2", @"3" ] mutableCopy]; 回答3: But, is there

Add values in NSMutableDictionary in iOS with Objective-C

自古美人都是妖i 提交于 2019-12-03 05:10:19
I'm starting objective-c development and I would like to ask the best way to implement a list of keys and values. In Delphi there is the class TDictionary and I use it like this: myDictionary : TDictionary<string, Integer>; bool found = myDictionary.TryGetValue(myWord, currentValue); if (found) { myDictionary.AddOrSetValue(myWord, currentValue+1); } else { myDictionary.Add(myWord,1); } How can I do it in objective-c ? Is there equivalent functions to the above mentioned AddOrSetValue() or TryGetValue() ? Thank you. Tom Jefferys You'd want to implement your example along these lines: EDIT: /

How to get the key for a given object from an NSMutableDictionary?

若如初见. 提交于 2019-12-03 04:19:21
I have an object which is in an big NSMutableDictionary, and need to find out which key this has. So I want to look up that "table" from both columns. Not only with keys, but also with objects (to get keys). Is that possible? Look to the parent class (NSDictionary) - (NSArray *)allKeysForObject:(id)anObject Which will return a NSArray of all the keys for a given Object Value. BUT it does this by sending an isEqual message to each object of the Dictionary so for your large dataset this may not be best performance. Maybe you need to hold some form of additional indexing structure structure(s) to

looping through an NSMutableDictionary

大憨熊 提交于 2019-12-03 02:50:02
问题 How do I loop through all objects in a NSMutableDictionary regardless of the keys? 回答1: A standard way would look like this for(id key in myDict) { id value = [myDict objectForKey:key]; [value doStuff]; } 回答2: you can use [myDict enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) { // do something with key and obj }]; if your target OS supports blocks. 回答3: You can use [dict allValues] to get an NSArray of your values. Be aware that it doesn't guarantee any order between calls.

Cocoa's NSDictionary: why are keys copied?

不羁的心 提交于 2019-12-03 01:28:47
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 forKey:[NSValue valueWithPointer:keyObject]]; ("When I come back and hand you this same key object instance again, get me that same value out.") ...which is exactly what I end up doing to get around this design sometimes. (Yes, I know about NSMapTable in desktop Cocoa

looping through an NSMutableDictionary

♀尐吖头ヾ 提交于 2019-12-02 14:47:17
How do I loop through all objects in a NSMutableDictionary regardless of the keys? A standard way would look like this for(id key in myDict) { id value = [myDict objectForKey:key]; [value doStuff]; } you can use [myDict enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) { // do something with key and obj }]; if your target OS supports blocks. You can use [dict allValues] to get an NSArray of your values. Be aware that it doesn't guarantee any order between calls. For simple loop, fast enumeration is a bit faster than block-based loop It's easier to do concurrent or reverse

iPhone: preserve NSUserDefaults values when application is killed

ε祈祈猫儿з 提交于 2019-12-02 13:40:01
问题 I am trying to implement "Add to Favorites" functionality using NSUserDefaults. So far I have written following code. - (void)favouriteButtonClicked:(id)sender { favselected = !favselected; // favselected is BOOL property MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; NSString* viewname = @"custom"; if(favselected) { [favButton setBackgroundImage:[UIImage imageNamed:@"selected.png"] forState:UIControlStateNormal]; [appDelegate addTOFavourites:self

Getting Top 10 Highest Numbers From Array?

≯℡__Kan透↙ 提交于 2019-12-02 11:58:43
问题 I am having a bit of a issue. I have an NSMutableDictionary with 10 NSMutableArrays in it. Each array has somewhere between 0-10 numbers which could each be any integer, e.g. 12 or 103. What I need to do is get the top 10 highest numbers from across each of the arrays. The trouble is, I need to keep a reference of the array it came from in the dictionary (the key) and the index position of the number from the array it came form. 回答1: Easiest way, is to sort the array in Descending order, and