Anybody can help me with code or hints for sorting my tableView according to the date. I think i have to use NSDate. I have an array already ready with NSDate type instances.
Thanks in advance.
            Asked
            
        
        
            Active
            
        
            Viewed 1,677 times
        
    0
            
            
        - 
                    1First help us with code… ;-) – vadian Jan 24 '16 at 13:29
2 Answers
1
            
            
        This post will most likely help you get what you are looking for.
Note: The tableview isn't what you want to sort. It is the array that you are using with the tableview that needs sorted.
 
    
    
        Community
        
- 1
- 1
 
    
    
        InSearchOf
        
- 170
- 4
- 
                    exactly the array i want to sort. I will check the link and give you my feedback. Thanks. – Kegham K. Jan 24 '16 at 14:33
1
            
            
        If you have array of dates than you can sort by comparing the date, here is the example.....
import UIKit
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        let dates = [
            NSDate(timeIntervalSince1970: 1453648103),
            NSDate(timeIntervalSince1970: 1453238129),
            NSDate(timeIntervalSince1970: 1453438129),
            NSDate(timeIntervalSince1970: 1453538129)
        ]
        print(dates)
        print(dates.sort({ $0.isLessThanDate($1) }))
    }
}
extension NSDate {
    func isLessThanDate(dateToCompare: NSDate) -> Bool {
        //Declare Variables
        var isLess = false
    //Compare Values
        if self.compare(dateToCompare) == NSComparisonResult.OrderedAscending {
            isLess = true
        }
        //Return Result
        return isLess
    }
}
 
    
    
        Rohit Parsana
        
- 166
- 7
 
    