我得到了NSDictionary对,如:
Key -> Value:
@"home" -> @"blue"
@"family" -> @"green"
@"work" -> @"red"
更新
互联网说没有人可以对 NSDictionary 进行排序:c
这段代码帮助我了解价值观。
sortedArray = [anArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
但是我失去了键和值之间的关系。如果有人可以编写函数,该函数采用 NSDictionary 并创建两个 NSArray,它们相关且其中一个数组按 NSDictionary 的值排序,如下所示:
(unsorted)
Key -> Value:
@"work" -> @"red"
@"home" -> @"blue"
@"family" -> @"green"
转换成:
Arrays, which keep relationship by index of item and one of them (values of NSDictionary) sorted
ArrayOfKeys = {@"home",@"family",@"work"}
ArrayOfValues = {@"blue", @"green", @"red"} -- this one sorted like alphabet