Nil Optionals not working on Xcode Playgrounds (Runtime error)

Not sure if I did something wrong or if this is a bug with Xcode Playgrounds. I ran this code and it always breaks in a playground but works fine in a project.

struct Reminder {
   var url: URL? = nil
   var urlComponent: URLComponents? = nil
   var string: String? = nil
var reminder = Reminder() //error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x7ffee5fd8990).The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

It won't let me set any optional URL or URLCompenents to nil. Optional String works for some reason.

I tested this here in my office (Xcode 12.3 on macOS 10.15.7 with a macOS > Blank playground). The only change I made to your code was to add an import Foundation at the top. It didn’t fail.

I don’t think there’s anything fundamentally broken about the code you posted, so the failure you’re seeing is definitely bugworthy. When you file the bug, make sure to include version information because clearly this isn’t happening everywhere.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

1 Like

Fails on my machine! (I get the same error as above.)

Xcode 12.3, macOS 11.1

1 Like

Interesting. Works on mine. Xcode 12.3, macOS 11.1, Mac mini M1.

1 Like

Still getting this. Xcode 12.5, macOS 11.4

Yes, do see this problem in Xcode Version 12.5 (12E262) playground.

It's fine in MacOS command line tool