nsmutabledictionary

Sort NSMutableDictionary keys by object?

强颜欢笑 提交于 2019-12-25 02:20:19
问题 Okeh. Here is the deal: Have have a NSMutualDictionary with words as keys (say names). The value objects is a NSNumber (like rating) NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; [dictionary setObject:[NSNumber intValue:1] forKey:@"Melvin"]; [dictionary setObject:[NSNumber intValue:2] forKey:@"John"]; [dictionary setObject:[NSNumber intValue:3] forKey:@"Esben"]; I want to sort them with the highest ratings first. I know I'm going to do it like this: [searchWords

NSMutableDictionary as datasource: can´t remove cell

☆樱花仙子☆ 提交于 2019-12-24 19:52:27
问题 I use a NSMutableDictionary to populate my UITableView, which works just fine. However, I want to delete rows and then I have to remove the target cell from the Dictionary before I call the -reloadData method. I´m having a hard time getting to the right object in the NSMutableDictionary and delete it. I´ll post the structure below. country = [ { citys = [ { id = 4; cityName = New York; }, { id = 5; cityName = LA; } ]; id = 2; countryName = US; }, { citys = [ { id = 21; cityName = Oslo; } ];

Dictionary Key Sort Options - Alpha then Numeric

 ̄綄美尐妖づ 提交于 2019-12-24 10:08:57
问题 All, I would like to sort this mutable dictionary of arrays keys like so: A-Z 0-9 but it's coming back sorted 0-9 A-Z. How can I sort it such that the alpha chars come before the numbers? Perhaps there is a built-in method that does this or should I create a category that extends NSString? NSArray *sKeysArray = [[listContent allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; NSString *sectionKey = [sKeysArray objectAtIndex:section]; NSArray *sectionValues = [listContent

Is there any ordered dictionary collection in IOS 5?

半世苍凉 提交于 2019-12-24 09:14:57
问题 My issue is I am using the table data source from the dictionary. This dictionary contains more than 20 elements in it. I need to search the element present in the dictionary and I need to scroll that element to a visible cell. My issue is I found the element, but it is out of the visible area. I need to scroll that to a visible area. How can I get the index? 回答1: Short answer? Nope. I know the feeling though, which lead me to... Longer answer? Yes-ish? My search a little while back brought

How should {array|dictionary}WithCapacity be used? [duplicate]

允我心安 提交于 2019-12-24 07:18:56
问题 This question already has answers here : NSMutableArray initWithCapacity nuances (2 answers) Closed 5 years ago . When I use NSMutableArray or NSMutableDictionary , if I know the number of elements I want to put in or the max number of elements, I usually create them with arrayWithCapacity or dictionaryWithCapacity , but I wonder does it really help to specify an (initial) capacity for the array/dictionary? I don't know how it is implemented internally, but I believe it is possible that when

Reading and writing NSMutableDictionary to a plist file

只谈情不闲聊 提交于 2019-12-23 23:38:20
问题 I am trying to save NSMutableDictionary in applicationDidEnterBackground of AppDelegate.m an to a plist file. Immediately after saving it, I try to check if the file exists and read it back, but the file is not found. NSString *photoCacheFilename = @"photoCache.plist"; [photoDict writeToFile:photoCacheFilename atomically:YES]; NSLog(@"File name: %@", photoCacheFilename); BOOL isFile = [[NSFileManager defaultManager] fileExistsAtPath:photoCacheFilename]; if(isFile) { NSLog (@"File found");

Swift mutable dictionary being treated as immutable

自作多情 提交于 2019-12-23 20:31:47
问题 I am trying to implement In App Purchases, and I am tracking which purchases a user has purchased via NSUserDefaults . I have a function that sets the values of each purchase, but when it runs, I get an error saying that I am mutating the dictionary of purchase values even though the dictionary is declared with a var instead of a let and is an NSMutableDictionary . Sometimes it does work, but most of the time it doesn't. I get a few warnings about declaring my variables with let instead of

Sum duplicate on NSMutableArray

随声附和 提交于 2019-12-23 03:32:08
问题 I have a NSMutableArray with objects of type NSMutableDictionary , the NSMutableDictionary contains 2 keys -Airlines (string) -Rating (integer) I have an NSMutableArray with all the objects and what i need is to Sum the rating of all the airline companies repeated objects, an example: Airline Rating A 2 B 3 B 4 C 5 The end result array will be the A = 2, C = 5 and the Sum of B´s that is equal to 7. My code so far: for (int i = 0; i < arrayMealRating.count; ++i) { NSMutableDictionary *item =

NSMutableDictionary remove object at key path?

本秂侑毒 提交于 2019-12-22 14:48:40
问题 I've got a layered NSMutableDictionary object and i'd like to be able to remove dictionaries deeper down in the hierarchy. Is there a quick and easy way to do this, for example, a removeObjectAtKeyPath-like method? Can't seem to find one. Thanks! 回答1: Nothing built in, but your basic category method will do just fine: @implementation NSMutableDictionary (WSSNestedMutableDictionaries) - (void)WSSRemoveObjectForKeyPath: (NSString *)keyPath { // Separate the key path NSArray * keyPathElements =

NSMutableDictionary with UIButton* as keys - iPhone development

别来无恙 提交于 2019-12-21 08:07:51
问题 I'm new to iPhone development and I have a question that may have a very simple answer. I am trying to add buttons to a view and these buttons are associated with a custom class that I defined. When I add the buttons to the view, I would like to know what class these buttons correspond to. This is because when I press the button, I need to get some information about the class, but the receiver of the message is another class. I couldn't find information about an error that I'm getting on the