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.current
returns aCalendar
, which is the Swift value wrapper type for the FoundationNSCalendar
type.dateComponents()
takes aSet<Calendar.Component>
and twoDate
arguments.Date
is the Swift value wrapper type forNSDate
.When existing Foundation APIs are imported into Swift, the types are bridged automatically, that why
NSCalendar.current
returns aCalender
and notNSCalendar
.The values types are preferred in Swift 3 because they provide proper value semantics and use
let
andvar
instead 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.