EXC_BAD_ACCESS(代码= 1,地址= 0x0)

时间:2016-01-14 08:24:06

标签: ios swift ios-simulator

我有一段代码可以在真实设备中正确运行,但在模拟器(iphone 6)中出现EXC_BAD_ACCESS (code=1, address=0x0)错误: enter image description here

bt输出为:

(lldb) bt
* thread #1: tid = 0xe40f6, 0x00000001052ab5e9 CoreFoundation`CFArrayGetCount + 25, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00000001052ab5e9 CoreFoundation`CFArrayGetCount + 25
  * frame #1: 0x0000000104c6a5af MyApp`static MyApp.SSID.fetchSSIDInfo (self=MyApp.SSID)() -> Swift.String + 95 at WifiGetter.swift:17
    frame #2: 0x0000000104c4994a MyApp`MyApp.TableViewController.sendWifi (self=0x00007ff05a64da80)() -> () + 26 at TableViewController.swift:355
    frame #3: 0x0000000104c49316 MyApp`MyApp.TableViewController.fetchData (self=0x00007ff05a64da80)() -> () + 38 at TableViewController.swift:308
    frame #4: 0x0000000104c4567f MyApp`MyApp.TableViewController.viewDidLoad (self=0x00007ff05a64da80)() -> () + 3215 at TableViewController.swift:66
    frame #5: 0x0000000104c45ea2 MyApp`@objc MyApp.TableViewController.viewDidLoad (MyApp.TableViewController)() -> () + 34 at TableViewController.swift:0
    frame #6: 0x00000001063c9931 UIKit`-[UIViewController loadViewIfRequired] + 1344
    frame #7: 0x000000010640cc26 UIKit`-[UINavigationController _layoutViewController:] + 54
    frame #8: 0x000000010640d4dd UIKit`-[UINavigationController _updateScrollViewFromViewController:toViewController:] + 433
    frame #9: 0x000000010640d633 UIKit`-[UINavigationController _startTransition:fromViewController:toViewController:] + 116
    frame #10: 0x000000010640e879 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 890
    frame #11: 0x000000010640f67d UIKit`-[UINavigationController __viewWillLayoutSubviews] + 57
    frame #12: 0x00000001065a763d UIKit`-[UILayoutContainerView layoutSubviews] + 248
    frame #13: 0x00000001062ef11c UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
    frame #14: 0x000000010c35836a QuartzCore`-[CALayer layoutSublayers] + 146
    frame #15: 0x000000010c34cbd0 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 366
    frame #16: 0x000000010c34ca4e QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
    frame #17: 0x000000010c3411d5 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 277
    frame #18: 0x000000010c36e9f0 QuartzCore`CA::Transaction::commit() + 508
    frame #19: 0x000000010c36f154 QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
    frame #20: 0x00000001053079d7 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    frame #21: 0x0000000105307947 CoreFoundation`__CFRunLoopDoObservers + 391
    frame #22: 0x00000001052fcebc CoreFoundation`CFRunLoopRunSpecific + 524
    frame #23: 0x000000010623998d UIKit`-[UIApplication _run] + 402
    frame #24: 0x000000010623e676 UIKit`UIApplicationMain + 171
    frame #25: 0x0000000104c20efd MyApp`main + 109 at AppDelegate.swift:20
    frame #26: 0x0000000108ea592d libdyld.dylib`start + 1

2 个答案:

答案 0 :(得分:3)

select to_number(hex_value,'xxxxxxx') from hex; 是零。你必须处理这个案子。我建议避免使用interfaces。在此处使类型不可选将允许!绑定正常工作。

答案 1 :(得分:0)

您应该将if let条款更改为if let interfaces = CNCopySupportedInterfaces() as? CFArray

因为if let interfaces: CFArray!使用!意味着强制解包,因此,当CNCopySupportedInterfaces()返回nil或无法转换为CFArray的值时,请强制解包会导致崩溃