我能否知道如何在swift中做到这一点?
Sort NSArray of custom objects based on sorting of another NSArray of strings
我尝试使用swift的方法
reduce ,过滤器,地图
但我没有得到结果
答案 0 :(得分:0)
刚刚将该代码转换为Swift"
func customSortFunction() {
var firstArray:Array = ["12","10","2"]
var attribute1 = Attribute(assetID: "10")
var attribute2 = Attribute(assetID: "2")
var attribute3 = Attribute(assetID: "12")
var secondArray = [attribute1, attribute2, attribute3]
secondArray.sort( { (find(firstArray, $0.assetID!))! < (find(firstArray, $1.assetID!))! } )
println("\(secondArray[0].assetID), \(secondArray[1].assetID), \(secondArray[2].assetID)")
}
属性类:
class Attribute {
var assetID: String?
init(let assetID:String) {
self.assetID = assetID
}
}