Arrays 在swift中对数组中的对象进行自定义排序
需要按字母顺序对对象(类/数据类型)进行排序 未排序数组::Arrays 在swift中对数组中的对象进行自定义排序,arrays,sorting,object,types,swift2,Arrays,Sorting,Object,Types,Swift2,需要按字母顺序对对象(类/数据类型)进行排序 未排序数组:: [main.Apple, main.Zoo, main.IceCream, main.Apple, main.IceCream] 排序数组::按字母顺序键入@前面 [main.Apple, main.Apple, main.IceCream, main.IceCream, main.Zoo] 这是我迄今为止找到的解决方案之一: 使用sortInPlace函数和dynamicType检查类名,例如:-String(firstData
[main.Apple, main.Zoo, main.IceCream, main.Apple, main.IceCream]
排序数组::按字母顺序键入@前面
[main.Apple, main.Apple, main.IceCream, main.IceCream, main.Zoo]
这是我迄今为止找到的解决方案之一:
sortInPlace
函数和dynamicType
检查类名,例如:-String(firstDataType.dynamicType)。组件由String(“.”)分隔。last代码>这将检索对象的类名
unsortedArray.sortInPlace({(firstDataType,secondDataType) in
return String(firstDataType.dynamicType).componentsSeparatedByString(".").last!
.localizedStandardCompare(String(secondDataType.dynamicType).componentsSeparatedByString(".").last!) == NSComparisonResult.OrderedAscending
})