Xcode停止在设备上工作

时间:2015-10-02 15:09:16

标签: ios xcode swift

非常新的xcode,应用程序在sim中运行良好。但设备正在抛出错误。使用Xcode 6.4,IOS 8.4.1。任何帮助将不胜感激!

很明白这个按钮是我的问题...

 @IBAction func SubmitBtn(Sender: AnyObject) {
        var url: NSString = "http://localhost:8888/databaseTest.php?x=\(textFromFirstName)&y=\(textFromLastName)&z=\(textFromCity)"
        var data = NSData(contentsOfURL: NSURL(string: url as String)!)
        var result = NSString(data: data!, encoding: NSUTF8StringEncoding)
        println(result)
    }

这是错误:

fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)

* thread #1: tid = 0xf7a6, 0x00327164 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) -> () + 64, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT, subcode=0xe7ffdefe)
  * frame #0: 0x00327164 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) -> () + 64
    frame #1: 0x000c4acc PlayerTrackingV3`PlayerTrackingV3.VerifyViewController.SubmitBtn (Sender=AnyObject at 0x00234020, self=0x14de20a0)(Swift.AnyObject) -> () + 1584 at VerifyViewController.swift:66
    frame #2: 0x000c4c24 PlayerTrackingV3`@objc PlayerTrackingV3.VerifyViewController.SubmitBtn (PlayerTrackingV3.VerifyViewController)(Swift.AnyObject) -> () + 104 at VerifyViewController.swift:0
    frame #3: 0x293e782a UIKit`-[UIApplication sendAction:to:from:forEvent:] + 70
    frame #4: 0x293e77d0 UIKit`-[UIControl sendAction:to:forEvent:] + 44
    frame #5: 0x293d2374 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 584
    frame #6: 0x293e7210 UIKit`-[UIControl touchesEnded:withEvent:] + 584
    frame #7: 0x293e6ee2 UIKit`-[UIWindow _sendTouchesForEvent:] + 522
    frame #8: 0x293e07f0 UIKit`-[UIWindow sendEvent:] + 540
    frame #9: 0x293b69b4 UIKit`-[UIApplication sendEvent:] + 196
    frame #10: 0x2962d0fe UIKit`_UIApplicationHandleEventFromQueueEvent + 14538
    frame #11: 0x293b53b6 UIKit`_UIApplicationHandleEventQueue + 1350
    frame #12: 0x25d1b00e CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
    frame #13: 0x25d1a422 CoreFoundation`__CFRunLoopDoSources0 + 222
    frame #14: 0x25d18aa0 CoreFoundation`__CFRunLoopRun + 768
    frame #15: 0x25c646d0 CoreFoundation`CFRunLoopRunSpecific + 476
    frame #16: 0x25c644e2 CoreFoundation`CFRunLoopRunInMode + 106
    frame #17: 0x2d6021a8 GraphicsServices`GSEventRunModal + 136
    frame #18: 0x29416444 UIKit`UIApplicationMain + 1440
    frame #19: 0x000d24fc PlayerTrackingV3`main + 196 at AppDelegate.swift:12

完全不知道为什么它在sim中运行,并且直到最近才在设备上正常工作。并且代码中没有任何变化。

1 个答案:

答案 0 :(得分:0)

您的错误就在这一行:

var result = NSString(data: data!, encoding: NSUTF8StringEncoding)

你的data是零,并说data!你打开一个nil的可选项,它是不可能的,它会抛出异常。

如果var data正在获取正确的内容,请验证您的contentsOfURL: