更新时间:2023-10-02 16:14:04
你可以使用集合.创建时会自动删除重复项.
You could use sets. Duplicates will be removed automatically upon creation.
NSArray *cleanedArray = [[NSSet setWithArray:dates] allObjects];
请记住,集合是无序的.
Bear in mind that a set is unordered.
根据 Brent 的评论,该问题的最新解决方案将允许您保持元素有序.
As per Brent's comment, a more recent solution to the problem that will allow you to keep the elements in order.
[[NSOrderedSet orderedSetWithArray:dates] array]