NSRangeException Xcode

时间:2015-06-21 02:36:09

标签: ios core-data nsrangeexception

我的应用和CoreData出现问题。我使用CoreData来保存用户信息,我花了很长时间搜索如何正确使用核心数据。我发现并且我学会了如何使用,但是当我从IOS模拟器中删除应用程序时问题就开始了。当我这样做时,应用程序冻结并且控制台中出现跟随错误:

    2015-06-20 23:20:23.141 AppName[1767:218797] *** Terminating        
    app due to uncaught exception 'NSRangeException', reason: '*** -
    [__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
    *** First throw call stack:
    (
0   CoreFoundation                      0x000000010a70ec65 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010c279bb7 objc_exception_throw + 45
2   CoreFoundation                      0x000000010a60517e -[__NSArrayI objectAtIndex:] + 190
3   YoutubeBillionaire                  0x000000010a103df2 _TFC18YoutubeBillionaire14ViewController11viewDidLoadfS0_FT_T_ + 2562
4   YoutubeBillionaire                  0x000000010a1059f2 _TToFC18YoutubeBillionaire14ViewController11viewDidLoadfS0_FT_T_ + 34
5   UIKit                               0x000000010b0de210 -[UIViewController loadViewIfRequired] + 738
6   UIKit                               0x000000010b0de40e -[UIViewController view] + 27
7   UIKit                               0x000000010aff92c9 -[UIWindow addRootViewControllerViewIfPossible] + 58
8   UIKit                               0x000000010aff968f -[UIWindow _setHidden:forced:] + 247
9   UIKit                               0x000000010b005e21 -[UIWindow makeKeyAndVisible] + 42
10  UIKit                               0x000000010afa9457 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2732
11  UIKit                               0x000000010afac1de -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
12  UIKit                               0x000000010afab0d5 -[UIApplication workspaceDidEndTransaction:] + 179
13  FrontBoardServices                  0x000000010dd895e5 __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 21
14  CoreFoundation                      0x000000010a64241c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
15  CoreFoundation                      0x000000010a638165 __CFRunLoopDoBlocks + 341
16  CoreFoundation                      0x000000010a637f25 __CFRunLoopRun + 2389
17  CoreFoundation                      0x000000010a637366 CFRunLoopRunSpecific + 470
18  UIKit                               0x000000010afaab42 -[UIApplication _run] + 413
19  UIKit                               0x000000010afad900 UIApplicationMain + 1282
20  YoutubeBillionaire                  0x000000010a1192e7 main + 135
21  libdyld.dylib                       0x000000010c9d1145 start + 1
   )
    libc++abi.dylib: terminating with uncaught exception of type NSException
    (lldb) 

谢谢大家。

1 个答案:

答案 0 :(得分:0)

错误非常明显;您正在尝试访问空数组中的值。您的CoreData请求不得返回任何结果。在尝试访问其中的元素之前,请确保检查空数组。如果从设备/模拟器中删除应用程序,它会删除CoreData中的所有数据,因此任何请求都将返回一个空数组。

相关问题