NSRangeException Xcode
NSRangeException Xcode
我的应用和 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)
谢谢大家
这个错误是不言自明的;您正在尝试访问空数组中的值。您的 CoreData 请求不得 returning 任何结果。确保在尝试访问其中的元素之前检查空数组。如果您从 device/the 模拟器中删除您的应用程序,它会删除 CoreData 中的所有数据,因此任何请求都会 return 一个空数组。
我的应用和 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)
谢谢大家
这个错误是不言自明的;您正在尝试访问空数组中的值。您的 CoreData 请求不得 returning 任何结果。确保在尝试访问其中的元素之前检查空数组。如果您从 device/the 模拟器中删除您的应用程序,它会删除 CoreData 中的所有数据,因此任何请求都会 return 一个空数组。