对包含NSDate对象的NSArray进行排序 [英] Sorting NSArray containing NSDate objects

查看:98
本文介绍了对包含NSDate对象的NSArray进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 NSDate 对象的数组。使用Objective-C,我可以使用以下方法对此数组进行排序:

I have an array containing NSDate objects. With Objective-C, I am able to sort this array by using:

NSArray *array = [unsortedArray sortedArrayUsingSelector:@selector(compare:)]

我想知道是否有Swift等同于做同样的事情。这里对Swift相对较新,黑客入侵。

I'm wondering if there's a Swift equivalent of doing this same thing. Relatively new to Swift here, hacking my way through.

推荐答案

使用原生数组输入Swift。如果您要与ObjC的遗留代码连接,请使用:

Using the native Array type in Swift. If you are interfacing with legacy code from ObjC, use this:

let array = unsortedArray.sortedArrayUsingSelector("compare:")

这篇关于对包含NSDate对象的NSArray进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆