斯威夫特我可以知道同样的事情是怎么发生的吗?

时间:2014-07-04 04:14:16

标签: ios swift

我能否知道如何在swift中做到这一点?

Sort NSArray of custom objects based on sorting of another NSArray of strings

我尝试使用swift的方法

  

reduce 过滤器地图

但我没有得到结果

1 个答案:

答案 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
}

}