This is my code. But an error said, cannot invoke dateComponent with an argument list of type...
let fromDate = NSDate(timeIntervalSince1970: TimeInterval(tweetsArray[indexPath.row].timestamp)!)
let toDate = NSDate()
let components : NSCalendar.Unit = [.second, .minute, .hour, .day, .weekOfMonth]
let differenceOfDate = NSCalendar.current.dateComponents(components, from: fromDate, to: toDate)
In Swift 3,
NSCalendar.currentreturns aCalendar, which is the Swift value wrapper type for the FoundationNSCalendartype.dateComponents()takes aSet<Calendar.Component>and twoDatearguments.Dateis the Swift value wrapper type forNSDate.When existing Foundation APIs are imported into Swift, the types are bridged automatically, that why
NSCalendar.currentreturns aCalenderand notNSCalendar.The values types are preferred in Swift 3 because they provide proper value semantics and use
letandvarinstead of immutable and mutable variants.Putting it all together:
For more information about Swift 3 value wrapper types and their corresponding Foundation types, see SE-0069 Mutability and Foundation Value Types, or the section "Bridged Types" in Working with Cocoa Frameworks in the "Using Swift with Cocoa and Objective-C" reference.