I'm very new at Swift and Objective-C.
I have a table view controller in which I have declared a dictionary and an array:
var parts = [:]
var partsSectionTitles: NSArray!
In my viewDidLoad function, I have:
parts = [
"Part 1" : ["X:1", "X:2", "X:3"],
"Part 2" : ["X:1", "X:2"],
"Part 3" : ["X:1"]
]
var partsSectionTitles = parts.allKeys
I've already successfully completed this table view controller in Objective-C, and in order to sort the partsSectionTitles alphabetically, I used:
partsSectionTitles = [[parts allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
So, my question is: How do I write the preceding Objective-C code in Swift? Thank you in advance for your answers.
UPDATE: I was able to solve the problem using bits and pieces from the answers you guys provided. So, thank you! Here's what I have:
I declared the parts dictionary as:
var parts = [String:[String]]()
which allowed me to provide multiple values to each key. This was a HUGE help.
Then I was able to create the partsSectionTitles and sort it:
partsSectionTitles = [String](parts.keys)
partsSectionTitles.sort(){ $0 < $1 }
This worked as I received no errors.