I have a NSDictionary that parsed to an array one of the element is date, i tried using [startimeArray sortUsingSelector:@selector(compare:)];
(starttimeArray) is my date but it only arrange ascending. how can i sort in descending order. thanks
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
Swift 3.0
For anyone using swift 3.0 this DateHelper will save u some headache.
The above code is a snippet from one of my projects. It uses the helper class to sort my logs with most recent dates at the left of the array. The $ sign is a positional parameter
Sort the array by puting NO is ascending parameter:
You can use a comparator block
to reverse the order, just swap the dates
or — as
compare:
returns a NSComparisonResult, which is actually typedef'ed to integer see below — just multiply by -1I'd use the built-in
reverseObjectEnumerator
method ofNSArray
It's useful when you need the array sorted in ascending and descending order, so you can easily go back to the previous sort.
There is the swift solution for the checked solution :
In the Class where the Array elements are being initialized.
Then in the Class where your startimeArray is initialized:
Then in the main():