【发布时间】:2018-08-12 16:17:15
【问题描述】:
我有一个函数,我想返回一个排序的字典
func sortDictonary()->[Int:String]
{
let dic:[Int:String] = [ 1:"B", 0:"A", 2:"C" ]
let sorted = dic.sorted(by: {$0.0 < $1.0} )
return sorted
}
但是我得到如下错误:
Cannot convert return expression of type '[(key: Int, value: String)]' to return type '[Int : String]'
如何将已排序的项目转换为标准字典
【问题讨论】:
-
我猜你不能保证标准字典的顺序,所以,要么我需要使用排序字典类型,要么想另一种方法来解决我的问题。我早该想到的。
标签: swift dictionary