EXC_BREAKPOINT(代码=1,子代码=0x18f6dd21c)Swift 游乐场 Xcode 13.3.1 中的错误
EXC_BREAKPOINT (code=1, subcode=0x18f6dd21c) error in Swift playground Xcode 13.3.1
作为 Swift 训练营挑战的一部分,我编写了以下代码。这段代码 运行 在 Replit 上完美无缺,但是当我 运行 在操场上 Xcode 13.3.1 中的代码时,我得到了一个巨大的错误块。请帮我弄清楚错误是什么。
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)
这是一条巨大的错误消息:
__lldb_expr_13/leapyYearusingIfElse.playground:25: 致命错误:在展开可选值时意外发现 nil
游乐场执行失败:
错误:执行被中断,原因:EXC_BREAKPOINT(代码=1,子代码=0x18f6dd21c)。
进程一直停留在中断点,使用"thread return -x" 到return 到表达式求值前的状态。
- 线程 #1,队列 = 'com.apple.main-thread',停止原因 = EXC_BREAKPOINT(代码=1,子代码=0x18f6dd21c)
- frame #0: 0x000000018f6dd21c libswiftCore.dylib
closure #1 (Swift.UnsafeBufferPointer<Swift.UInt8>) -> () in closure #1 (Swift.UnsafeBufferPointer<Swift.UInt8>) -> () in closure #1 (Swift.UnsafeBufferPointer<Swift.UInt8>) -> () in Swift._assertionFailure(_: Swift.StaticString, _: Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 356 frame #1: 0x000000018f6dcf84 libswiftCore.dylib
closure #1 (Swift.UnsafeBufferPointer) -> () in closure #1 (Swift.UnsafeBufferPointer) -> () in Swift.assertionFailure(: Swift.StaticString, _: Swift.StaticString, 文件:Swift.StaticString,行:Swift.UInt,标志:Swift.UInt32) -> Swift.Never + 192
帧 #2:0x000000018f6dc954 libswiftCore.dylibSwift._assertionFailure(_: Swift.StaticString, _: Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 228 frame #3: 0x0000000100510480 $__lldb_expr14
main 在 leapyYearusingIfElse.playground:0
第 4 帧:0x00000001000d33c8 leapyYearusingIfElselinkResources + 272 frame #5: 0x0000000180360580 CoreFoundation
CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 20
第 6 帧:0x000000018035f854 CoreFoundation__CFRunLoopDoBlocks + 408 frame #7: 0x000000018035a018 CoreFoundation
__CFRunLoopRun + 764
第 8 帧:0x0000000180359804 CoreFoundationCFRunLoopRunSpecific + 572 frame #9: 0x000000018c23660c GraphicsServices
GSEventRunModal + 160
第 10 帧:0x0000000184d7bd2c UIKitCore-[UIApplication _run] + 992 frame #11: 0x0000000184d808c8 UIKitCore
UIApplicationMain + 112
第 12 帧:0x00000001000d3488 leapyYearusingIfElsemain + 192 frame #13: 0x00000001003b9cd8 dyld_sim
start_sim + 20
第 14 帧:0x0000000100309088 dyld`start + 516
你的代码不能 运行 在操场上,尽管它可以 运行 在 repl 环境中,因为 readLine() returns nil.
您的代码试图强制解包 nil 值。
你应该放弃在操场上运行涉及readLine()的代码。
作为 Swift 训练营挑战的一部分,我编写了以下代码。这段代码 运行 在 Replit 上完美无缺,但是当我 运行 在操场上 Xcode 13.3.1 中的代码时,我得到了一个巨大的错误块。请帮我弄清楚错误是什么。
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)
这是一条巨大的错误消息:
__lldb_expr_13/leapyYearusingIfElse.playground:25: 致命错误:在展开可选值时意外发现 nil 游乐场执行失败:
错误:执行被中断,原因:EXC_BREAKPOINT(代码=1,子代码=0x18f6dd21c)。 进程一直停留在中断点,使用"thread return -x" 到return 到表达式求值前的状态。
- 线程 #1,队列 = 'com.apple.main-thread',停止原因 = EXC_BREAKPOINT(代码=1,子代码=0x18f6dd21c)
- frame #0: 0x000000018f6dd21c libswiftCore.dylib
closure #1 (Swift.UnsafeBufferPointer<Swift.UInt8>) -> () in closure #1 (Swift.UnsafeBufferPointer<Swift.UInt8>) -> () in closure #1 (Swift.UnsafeBufferPointer<Swift.UInt8>) -> () in Swift._assertionFailure(_: Swift.StaticString, _: Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 356 frame #1: 0x000000018f6dcf84 libswiftCore.dylib
closure #1 (Swift.UnsafeBufferPointer) -> () in closure #1 (Swift.UnsafeBufferPointer ) -> () in Swift.assertionFailure(: Swift.StaticString, _: Swift.StaticString, 文件:Swift.StaticString,行:Swift.UInt,标志:Swift.UInt32) -> Swift.Never + 192 帧 #2:0x000000018f6dc954 libswiftCore.dylib Swift._assertionFailure(_: Swift.StaticString, _: Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 228 frame #3: 0x0000000100510480 $__lldb_expr14
main 在 leapyYearusingIfElse.playground:0 第 4 帧:0x00000001000d33c8 leapyYearusingIfElselinkResources + 272 frame #5: 0x0000000180360580 CoreFoundation
CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 20 第 6 帧:0x000000018035f854 CoreFoundation__CFRunLoopDoBlocks + 408 frame #7: 0x000000018035a018 CoreFoundation
__CFRunLoopRun + 764 第 8 帧:0x0000000180359804 CoreFoundationCFRunLoopRunSpecific + 572 frame #9: 0x000000018c23660c GraphicsServices
GSEventRunModal + 160 第 10 帧:0x0000000184d7bd2c UIKitCore-[UIApplication _run] + 992 frame #11: 0x0000000184d808c8 UIKitCore
UIApplicationMain + 112 第 12 帧:0x00000001000d3488 leapyYearusingIfElsemain + 192 frame #13: 0x00000001003b9cd8 dyld_sim
start_sim + 20 第 14 帧:0x0000000100309088 dyld`start + 516
- frame #0: 0x000000018f6dd21c libswiftCore.dylib
你的代码不能 运行 在操场上,尽管它可以 运行 在 repl 环境中,因为 readLine() returns nil.
您的代码试图强制解包 nil 值。 你应该放弃在操场上运行涉及readLine()的代码。