I'm trying to compare NSDates. Basically, i want to know if both are same or not. i've googled it and found some solutions but they are applicable for iOS8+
What i'm doing right now is:
func isCurrentDate() -> Bool
{
let currentDate = NSDate()
if #available(iOS 8.0, *) {
let order = NSCalendar.currentCalendar().compareDate(currentDate, toDate: self,
toUnitGranularity: .Day)
if order == .OrderedSame {
return true
}
}
return false //This part need to be updated
}
i can do this by comparing date formatted strings "YYYY MM DD" (as following code), but i feel that it's not correct approach.
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "YYYY MM DD"
if dateFormatter.stringFromDate(currentDate) == dateFormatter.stringFromDate(self) {
return true
}
i've checked a few posts like this but it's in objective-c and i'm finding it difficult to translate the syntax for swift