相关疑难解决方法(0)

Swift如何按属性值对自定义对象数组进行排序

假设我们有一个名为imageFile的自定义类,该类包含两个属性.

class imageFile  {
    var fileName = String()
    var fileID = Int()
}
Run Code Online (Sandbox Code Playgroud)

很多都存储在Array中

var images : Array = []

var aImage = imageFile()
aImage.fileName = "image1.png"
aImage.fileID = 101
images.append(aImage)

aImage = imageFile()
aImage.fileName = "image1.png"
aImage.fileID = 202
images.append(aImage)
Run Code Online (Sandbox Code Playgroud)

问题是:如何通过'fileID'ASC或DESC对图像数组进行排序?

arrays sorting swift

474
推荐指数
16
解决办法
31万
查看次数

标签 统计

arrays ×1

sorting ×1

swift ×1