I've declared this dictionary:
var arrayFrasi:[String:String] = [:]
Then in the viewDidLoad I retrive the data from my db and then I sort the dictionary using this code:
let df = NSDateFormatter()
df.dateFormat = "dd-MM-yyyy"
let myArrayOfTuples = self.arrayFrasi.sort{ df.dateFromString($0.0)!.compare(df.dateFromString($1.0)!) == .OrderedAscending}
But I need to use the initial dictionary (arrayFrasi), when I do this:
self.arrayFrasi = myArrayOfTuples
I've got this error:
cannot assign value of type '[(string, string)]' to type '[string : string]'
I can't figure out why. Thank you very much!
That makes perfect sense. A Dictionary has no defined order, so the sort returns you an array of tuples.
Swift’s Dictionary type does not have a defined ordering. To iterate over the keys or values of a dictionary in a specific order, use the sort() method on its keys or values property.
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With