Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios EXC\u错误访问(代码=1,地址=0x0)_Ios_Swift_Ios Simulator - Fatal编程技术网

Ios EXC\u错误访问(代码=1,地址=0x0)

Ios EXC\u错误访问(代码=1,地址=0x0),ios,swift,ios-simulator,Ios,Swift,Ios Simulator,我有一段代码在真实设备中正确运行,但在模拟器(iphone 6)中给出了EXC\u BAD\u访问(code=1,address=0x0)错误: bt输出为: (lldb) bt * thread #1: tid = 0xe40f6, 0x00000001052ab5e9 CoreFoundation`CFArrayGetCount + 25, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, addr

我有一段代码在真实设备中正确运行,但在模拟器(iphone 6)中给出了
EXC\u BAD\u访问(code=1,address=0x0)
错误:

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

接口
为零。你必须处理这个案子。我建议避免使用
。此处将类型设置为非可选将允许
if let
绑定正常工作。

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


因为您使用了
if-let接口:CFArray
一起使用平均强制展开,因此,当
CNCopySupportedInterfaces()
返回
nil
或无法转换为
CFArray
的值时,强制展开将导致崩溃

请共享代码而不是屏幕截图。