我正在学习斯坦福大学的快速课程,我遇到了严重的问题。
我的问题是,当我在模拟器中运行我的应用程序时它工作得非常好,但是当我尝试在我的物理iPhone上运行它时会崩溃并显示错误消息"致命错误:在解开可选值时意外发现nil #34 ;.
import UIKit
class ViewController: UIViewController
{
@IBOutlet weak var display: UILabel!
var userIsInTheMiddleOfTypingANumber = false
@IBAction func appendDigit(sender: UIButton)
{
let digit = sender.currentTitle!
if userIsInTheMiddleOfTypingANumber
{
display.text = display.text! + digit
}
else
{
display.text = digit
userIsInTheMiddleOfTypingANumber = true
}
}
@IBAction func operate(sender: UIButton)
{
let operation = sender.currentTitle!
if userIsInTheMiddleOfTypingANumber
{
enter()
}
switch operation
{
case "×": performOperation(multiplay)
case "÷": performOperation(divide)
case "+": performOperation(add)
case "−": performOperation(minus)
default: break
}
}
func performOperation(operation: (Double, Double) -> Double)
{
if operandStack.count >= 2 {
displayValue = operation(operandStack.removeLast(), operandStack.removeLast())
enter()
}
}
func multiplay(op1: Double, op2: Double) -> Double {
return op1 * op2
}
func divide(op1: Double, op2: Double) -> Double {
return op1 / op2
}
func add(op1: Double, op2: Double) -> Double {
return op1 + op2
}
func minus(op1: Double, op2: Double) -> Double {
return op1 - op2
}
var operandStack = Array<Double>()
@IBAction func enter()
{
userIsInTheMiddleOfTypingANumber = false
operandStack.append(displayValue)
print("operandStack = \(operandStack)")
}
var displayValue: Double
{
get
{
return NSNumberFormatter().numberFromString(display.text!)!.doubleValue
}
set
{
display.text = "\(newValue)"
userIsInTheMiddleOfTypingANumber = false
}
}
}
此错误消息为:
libswiftCore.dylib`function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ():
0x1001dc740 <+0>: stp x29, x30, [sp, #-16]!
0x1001dc744 <+4>: mov x29, sp
0x1001dc748 <+8>: sub sp, sp, #16
0x1001dc74c <+12>: and w8, w2, #0x1
0x1001dc750 <+16>: tbnz w8, #0, 0x1001dc770 ; <+48>
0x1001dc754 <+20>: tbnz x1, #63, 0x1001dc7b4 ; <+116>
0x1001dc758 <+24>: add x1, x0, x1
0x1001dc75c <+28>: mov x2, x3
0x1001dc760 <+32>: mov x3, x4
0x1001dc764 <+36>: mov x4, x5
0x1001dc768 <+40>: bl 0x10021edd0 ; function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded> of Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ()).(closure #2)
-> 0x1001dc76c <+44>: brk #0x1 There it is!!!!
0x1001dc770 <+48>: str xzr, [sp, #8]
0x1001dc774 <+52>: cmp x0, w0, uxtw
0x1001dc778 <+56>: b.ne 0x1001dc94c ; <+524>
0x1001dc77c <+60>: lsr w8, w0, #11
0x1001dc780 <+64>: cmp w8, #26
0x1001dc784 <+68>: b.hi 0x1001dc7d8 ; <+152>
0x1001dc788 <+72>: cmp w0, #128
0x1001dc78c <+76>: b.lo 0x1001dc808 ; <+200>
0x1001dc790 <+80>: orr w8, wzr, #0x80
0x1001dc794 <+84>: bfxil x8, x0, #0, #6
0x1001dc798 <+88>: cmp w0, #2048
0x1001dc79c <+92>: b.hs 0x1001dc83c ; <+252>
0x1001dc7a0 <+96>: movz x10, #0
0x1001dc7a4 <+100>: movz x11, #0
0x1001dc7a8 <+104>: lsr w9, w0, #6
0x1001dc7ac <+108>: orr w9, w9, #0xffffffc0
0x1001dc7b0 <+112>: b 0x1001dc86c ; <+300>
0x1001dc7b4 <+116>: adr x0, #808224 ; "fatal error"
0x1001dc7b8 <+120>: nop
0x1001dc7bc <+124>: adr x3, #808724 ; "UnsafeBufferPointer with negative count"
0x1001dc7c0 <+128>: nop
0x1001dc7c4 <+132>: movz w1, #0xb
0x1001dc7c8 <+136>: orr w2, wzr, #0x2
0x1001dc7cc <+140>: movz w4, #0x27
0x1001dc7d0 <+144>: orr w5, wzr, #0x2
0x1001dc7d4 <+148>: bl 0x1001dc740 ; <+0>
0x1001dc7d8 <+152>: cmp w0, #14, lsl #12
0x1001dc7dc <+156>: b.lo 0x1001dc818 ; <+216>
0x1001dc7e0 <+160>: cmp w0, #272, lsl #12
0x1001dc7e4 <+164>: b.hs 0x1001dc900 ; <+448>
0x1001dc7e8 <+168>: orr w8, wzr, #0x80
0x1001dc7ec <+172>: bfxil x8, x0, #0, #6
0x1001dc7f0 <+176>: orr w9, wzr, #0xffffff80
0x1001dc7f4 <+180>: bfxil w9, w0, #6, #6
0x1001dc7f8 <+184>: lsr w10, w0, #16
0x1001dc7fc <+188>: cbnz w10, 0x1001dc924 ; <+484>
0x1001dc800 <+192>: lsr w10, w0, #12
0x1001dc804 <+196>: b 0x1001dc848 ; <+264>
0x1001dc808 <+200>: movz x9, #0
0x1001dc80c <+204>: movz x11, #0
0x1001dc810 <+208>: mov x8, x0
0x1001dc814 <+212>: b 0x1001dc89c ; <+348>
0x1001dc818 <+216>: adr x0, #808124 ; "fatal error"
0x1001dc81c <+220>: nop
0x1001dc820 <+224>: adr x3, #811328 ; "high- and low-surrogate code points are not valid Unicode scalar values"
0x1001dc824 <+228>: nop
0x1001dc828 <+232>: movz w1, #0xb
0x1001dc82c <+236>: orr w2, wzr, #0x2
0x1001dc830 <+240>: movz w4, #0x47
0x1001dc834 <+244>: orr w5, wzr, #0x2
0x1001dc838 <+248>: bl 0x1001dc740 ; <+0>
0x1001dc83c <+252>: lsr w10, w0, #12
0x1001dc840 <+256>: orr w9, wzr, #0xffffff80
0x1001dc844 <+260>: bfxil w9, w0, #6, #6
0x1001dc848 <+264>: movz x12, #0
0x1001dc84c <+268>: movz x11, #0
0x1001dc850 <+272>: orr w10, w10, #0xffffffe0
0x1001dc854 <+276>: and x10, x10, #0xff
0x1001dc858 <+280>: lsl x13, x12, #3
0x1001dc85c <+284>: lsl x10, x10, x13
0x1001dc860 <+288>: orr x11, x10, x11
0x1001dc864 <+292>: str x11, [sp, #8]
0x1001dc868 <+296>: add x10, x12, #1
0x1001dc86c <+300>: orr w12, wzr, #0x8
0x1001dc870 <+304>: umulh x12, x10, x12
0x1001dc874 <+308>: cmp xzr, x12
0x1001dc878 <+312>: b.ne 0x1001dc94c ; <+524>
0x1001dc87c <+316>: lsl x12, x10, #3
0x1001dc880 <+320>: cmp x12, #63
0x1001dc884 <+324>: b.hi 0x1001dc8dc ; <+412>
0x1001dc888 <+328>: and x9, x9, #0xff
0x1001dc88c <+332>: lsl x9, x9, x12
0x1001dc890 <+336>: orr x11, x9, x11
0x1001dc894 <+340>: str x11, [sp, #8]
0x1001dc898 <+344>: add x9, x10, #1
0x1001dc89c <+348>: orr w10, wzr, #0x8
0x1001dc8a0 <+352>: umulh x10, x9, x10
0x1001dc8a4 <+356>: cmp xzr, x10
0x1001dc8a8 <+360>: b.ne 0x1001dc94c ; <+524>
0x1001dc8ac <+364>: lsl x10, x9, #3
0x1001dc8b0 <+368>: cmp x10, #64
0x1001dc8b4 <+372>: b.hs 0x1001dc8dc ; <+412>
0x1001dc8b8 <+376>: and x8, x8, #0xff
0x1001dc8bc <+380>: lsl x8, x8, x10
0x1001dc8c0 <+384>: orr x8, x8, x11
0x1001dc8c4 <+388>: str x8, [sp, #8]
0x1001dc8c8 <+392>: add x8, sp, #8
0x1001dc8cc <+396>: add x8, x9, x8
0x1001dc8d0 <+400>: add x1, x8, #1
0x1001dc8d4 <+404>: add x0, sp, #8
0x1001dc8d8 <+408>: b 0x1001dc75c ; <+28>
0x1001dc8dc <+412>: adr x0, #807928 ; "fatal error"
0x1001dc8e0 <+416>: nop
0x1001dc8e4 <+420>: adr x3, #808332 ; "shift amount is larger than type size in bits"
0x1001dc8e8 <+424>: nop
0x1001dc8ec <+428>: movz w1, #0xb
0x1001dc8f0 <+432>: orr w2, wzr, #0x2
0x1001dc8f4 <+436>: movz w4, #0x2d
0x1001dc8f8 <+440>: orr w5, wzr, #0x2
0x1001dc8fc <+444>: bl 0x1001dc740 ; <+0>
0x1001dc900 <+448>: adr x0, #807892 ; "fatal error"
0x1001dc904 <+452>: nop
0x1001dc908 <+456>: adr x3, #811176 ; "value is outside of Unicode codespace"
0x1001dc90c <+460>: nop
0x1001dc910 <+464>: movz w1, #0xb
0x1001dc914 <+468>: orr w2, wzr, #0x2
0x1001dc918 <+472>: movz w4, #0x25
0x1001dc91c <+476>: orr w5, wzr, #0x2
0x1001dc920 <+480>: bl 0x1001dc740 ; <+0>
0x1001dc924 <+484>: lsr w10, w0, #18
0x1001dc928 <+488>: orr w11, w10, #0xf0
0x1001dc92c <+492>: cmp w11, w11, uxtb
0x1001dc930 <+496>: b.ne 0x1001dc94c ; <+524>
0x1001dc934 <+500>: orr w10, wzr, #0xffffff80
0x1001dc938 <+504>: bfxil w10, w0, #12, #6
0x1001dc93c <+508>: and x11, x11, #0xff
0x1001dc940 <+512>: str x11, [sp, #8]
0x1001dc944 <+516>: orr w12, wzr, #0x1
0x1001dc948 <+520>: b 0x1001dc854 ; <+276>
0x1001dc94c <+524>: brk #0x1