Swift how to sort array of custom objects by property value

前端 未结 18 2177
逝去的感伤
逝去的感伤 2020-11-22 02:12

lets say we have a custom class named imageFile and this class contains two properties.

class imageFile  {
    var fileName = String()
    var fileID = Int(         


        
18条回答
  •  走了就别回头了
    2020-11-22 02:35

    Swift 3 & 4 & 5

    I had some problem related to lowercase and capital case

    so I did this code

    let sortedImages = images.sorted(by: { $0.fileID.lowercased() < $1.fileID.lowercased() })
    

    and then use sortedImages after that

提交回复
热议问题