Optional (but non-nil) NSDate is nil when assigned to Date?

I have an Objective-C class which contains an NSDate *createdTime property. When using an object of this class from Swift, accessing createdTime and assigning it to a variable of type Date results in nil being assigned to the variable. This behavior can also be seen in LLDB, where p createdTime prints nil but po createdTime prints the date:

(lldb) p obj.createdTime
(Date?) $R60 = nil
(lldb) po obj.createdTime
▿ Optional<Date>
  ▿ some : 2015-04-07 14:05:29 +0000
    - timeIntervalSinceReferenceDate : 450108329.0

(lldb) p (obj.createdTime as NSDate?)
(NSDate?) $R66 = some {
  some = 0x803059aa219d0795 2015-04-07 14:05:29 UTC
}
(lldb) p (obj.createdTime as NSDate?) as Date?
(Date?) $R68 = nil

What is going on?

This looks like you may be hitting https://bugs.swift.org/browse/SR-12724 (LLDB can falsely report that a variable holds nil)

2 Likes

Thanks @harlanhaskins. That looks like exactly the issue I'm hitting!

See also https://bugs.swift.org/browse/SR-12444

When I filed a similar radar with apple it said at the top of the screen that similar bugs had been reported "more than ten times."

1 Like
Terms of Service

Privacy Policy

Cookie Policy