swiftxcodeplaygrounds

EXC_BREAKPOINT (code=1, subcode=0x18f6dd21c) error in Swift playground Xcode 13.3.1


I have written the following code as part of Swift bootcamp challenge. This code runs perfectly on Replit but when I run the code on the playground in Xcode 13.3.1 I get a huge block of error. Please help me figure out whats the error about.

var aYear =  Int(readLine()!)!

func isLeap(year: Int) {
  if year % 4 == 0 && year % 400 == 0 && year % 100 == 0 {
    print("Yes")
  } else {
    print("No")
  }
}

isLeap(year: aYear)

Here's the huge error message:

__lldb_expr_13/leapyYearusingIfElse.playground:25: Fatal error: Unexpectedly found nil while unwrapping an Optional value Playground execution failed:

error: Execution was interrupted, reason: EXC_BREAKPOINT (code=1, subcode=0x18f6dd21c). The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.


Solution

  • Your code cannot run on the playground even though it can run on repl environment because readLine() returns nil.

    Your code attempts to unwrap the nil value forcibly. You should give up operating the code involving readLine() on the playground.