Sorting NSMutableArray with objects in it

This question already has an answer here:

  • How do I sort an NSMutableArray with custom objects in it? 25 answers

  • 你必须使用一个块的sort功能:

    struct Fruit {
        var title: String
        var desc: String
    }
    
    var fruits = [Fruit]()
    fruits.append(Fruit(title: "a", desc: "b"))
    fruits.append(Fruit(title: "c", desc: "d"))
    
    
    let sorted = fruits.sort() { $0.title > $1.title }
    sorted
    

    它应该是sortUsingDescriptors:not sortedArrayUsingDescriptors:

    链接地址: http://www.djcxy.com/p/70828.html

    上一篇: NSMutableArray与对象排序

    下一篇: 将NSMutableArray与其中的对象进行排序