Wednesday, 15 April 2015

ios - Sorting a nsdictionary, how does it work? -


I have a problem understanding this problem compare-selector / <> compare code

I have the following code, I am trying to sort key and sort them at the same time. But, it is not sorted Output NSArray's order does not matter what I do. NSMutableDictionary * dictToSort = [[NSMutableDictionary alloc] initWithObjectsAndKeys: @ "Joe", [NSNumber NumberHome: 2], @ "Icon", [NSNumber Number with Int: 1], @ "M Dirk ", [NSNumber numberAttah: 3], zero]; NSArray * dictToSortKeys = [dictToSort keysService given user selector: @sillector (compare :)); NSLog (@ "Not Sorted"); NSNumber * xx = dictToSortKeys [0]; NSNumber * xy = dictToSortKeys [1]; NSNumber * Xz = DecoSortCas [2]; NSLog (@ "Sorted% d% d% d", xx.integerValue, xy.integerValue, xz.integerValue); I do not find how this code is computed: The function's function says that it gives NSOrderedAscending, NSOrderedSame or NSOrderedDescending , But there is no way to get these returns. And also, this is considered magical work? The documentation for this comparative thing is pretty bad.

I think you are confused about that keysSortedByValueUsingSelector: It converts dictionary entries by value , and returns the key in that sequence.

These entries are in your dictionary:

  Key value - ----- 1 digit 2 that is 3 mdark   

< Code> keys Selectable Value Selector: The method effectively applies that table to a "????" Organizes by Value? Column:

  Key value -------- 2 which is 1 point 3 mdark   

(Note that joe Before the alphabet> symbol and symbol before the spectrum occurs before mdark .)

Then one of the key Array returns, Order is computed only in: @ [@ 2, @ 1, @ 3] .

Note that the keysBibleUser Selector: never compares keys, it compares values ​​to only .

If you want to sort key by itself using the key, do this:

  NSArray * dictToSortKeys = [DictToSort.allKeys is sorted by User: @Selector (compare Please :) :);    

No comments:

Post a Comment