Try adding to optional data:
if let date = nsdate as Date?
You are trying to make the optional composition of the optional NSDate < optional date. So far, NSDate connecting to obj-c on Date , so this listing always succeeds, so the optional addition required here is as simple as casting. Then you need to specify an optional value, so the final value should be optional, so Date? fits here.
source share