I can get an array of dictionary keys sorted by values, but how to I get an array of values sorted by dictionary keys? I've been looking everywhere with no luck. Any help appreciated.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- “Zero out” sensitive String data in Swift
- back button text does not change
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
One way is to construct the array of sorted dictionary keys, then create another array of the values based on the array of keys:
This might work:
or in Swift
or
…and that is why you should start developing in Swift
I created a category on NSDictionary to get this accomplished:
My experience shows that sorting
NSDictionary
by keys is not much useful. Although afterlogging
theNSDictionary
they seem to be sorted, when needed to put them in a tableview they are not in order any more.I suggest storing the keys in an
NSArray
property and then query theNSDictionary
objects according to the order of the keys in theNSArray
.