应用程序崩溃了 dispatch_once 块的多个调用?

App is crashing multliple calls of dispatch_once block?

这是错误:

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayI objectAtIndex:]: index 18446744073709551615 beyond bounds [0 .. 1]'

*** First throw call stack:
(
    0   CoreFoundation                      0x0000000104b09f45 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000104edbdeb objc_exception_throw + 48
    2   CoreFoundation                      0x00000001049f8b14 -[__NSArrayI objectAtIndex:] + 164
    3   MyApp                       0x000000010234ae4b -[AppManager homePage] + 203
    4   MyApp                       0x000000010234a437 -[AppManager init] + 503
    5   MyApp                       0x000000010234a222 __28+[AppManager sharedInstance]_block_invoke + 50
    6   libdispatch.dylib                   0x00000001061da49b _dispatch_client_callout + 8
    7   libdispatch.dylib                   0x00000001061c5e28 dispatch_once_f + 543
    8   MyApp                       0x000000010234a1cb +[AppManager sharedInstance] + 107
    9   MyApp                       0x000000010238494b -[SplashViewController viewDidLoad] + 379
    10  UIKit                               0x0000000103652cc4 -[UIViewController loadViewIfRequired] + 1198
    11  UIKit                               0x00000001036970ee -[UINavigationController _layoutViewController:] + 54
    12  UIKit                               0x00000001036979c2 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 462
    13  UIKit                               0x0000000103697b34 -[UINavigationController _startTransition:fromViewController:toViewController:] + 126
    14  UIKit                               0x0000000103698d8d -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
    15  UIKit                               0x0000000103699cea -[UINavigationController __viewWillLayoutSubviews] + 57
    16  UIKit                               0x000000010383fc85 -[UILayoutContainerView layoutSubviews] + 248
    17  UIKit                               0x0000000103574e40 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
    18  QuartzCore                          0x000000010324059a -[CALayer layoutSublayers] + 146
    19  QuartzCore                          0x0000000103234e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    20  QuartzCore                          0x0000000103234cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    21  QuartzCore                          0x0000000103229475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    22  QuartzCore                          0x0000000103256c0a _ZN2CA11Transaction6commitEv + 486
    23  QuartzCore                          0x000000010325737c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    24  CoreFoundation                      0x0000000104a35947 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    25  CoreFoundation                      0x0000000104a358b7 __CFRunLoopDoObservers + 391
    26  CoreFoundation                      0x0000000104a2ae2c CFRunLoopRunSpecific + 524
    27  UIKit                               0x00000001034bb4f5 -[UIApplication _run] + 402
    28  UIKit                               0x00000001034c030d UIApplicationMain + 171
    29  MyApp                       0x000000010239b63f main + 111
    30  libdyld.dylib                       0x000000010620e92d start + 1
    31  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我没有访问 NSArray 中的任何对象,这会导致以下错误,但肯定是我的应用程序给了我这个错误。

错误出在您的 homePage 方法中,您可以在此处查看:

2   CoreFoundation  ... -[__NSArrayI objectAtIndex:] + 164
3   MyApp           ... -[AppManager homePage] + 203   <----THIS CALLS objectAtIndex: ABOVE

根据错误信息,它正在尝试访问索引18446744073709551615。这是NSNotFound的值,这意味着您可能处理NSNotFound不正确!

-[AppManager homePage] 方法出现问题,请检查是否有任何数组在那里访问