iosswiftnsrangeexception

NSRangeException at particular Segue


I have this particular segue that keeps giving me NSRangeException. I have no code at all in prepareForSegue. I put a break point in viewdidload of that view controller and it is executed with no problem. Seems that the exception occurs in IOS system code.

This is detail of exception

2015-09-16 07:21:24.939 Vote Strategic[7523:1117149] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' *** First throw call stack: ( 0 CoreFoundation 0x000000010a699c65 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010c204bb7 objc_exception_throw + 45 2 CoreFoundation 0x000000010a583093 -[__NSArrayM objectAtIndex:] + 227 3 My Strategic 0x000000010a008cfa _TPAo13 + 42 4 My Strategic 0x000000010a009c35 _TTRXFo_dSi_aPSs9AnyObject__XFo_dSi_oPS_ + 21 5 My Strategic 0x000000010a0094ec _TFFC14My_Strategic4Rest9getRidingFS0_FSST_U_FTGSQCSo13NSURLResponse_GSQCSo6NSData_GSQCSo7NSError__T_ + 1260 6 My Strategic 0x000000010a009cea _TTRXFo_oGSQCSo13NSURLResponse_oGSQCSo6NSData_oGSQCSo7NSError__dT__XFdCb_dGSQS__dGSQS0__dGSQS1___dT__ + 90 7 CFNetwork 0x000000010c8a98c5 67+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]_block_invoke_2 + 155 8 Foundation 0x000000010ab5a57f __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK + 7 9 Foundation 0x000000010aa9b0b2 -[NSBlockOperation main] + 98 10 Foundation 0x000000010aa7d774 -[__NSOperationInternal _start:] + 645 11 Foundation 0x000000010aa7d383 __NSOQSchedule_f + 184 12 libdispatch.dylib 0x000000010dcfe614 _dispatch_client_callout + 8 13 libdispatch.dylib 0x000000010dce56a7 _dispatch_queue_drain + 2176 14 libdispatch.dylib 0x000000010dce4cc0 _dispatch_queue_invoke + 235 15 libdispatch.dylib 0x000000010dce83b9 _dispatch_root_queue_drain + 1359 16 libdispatch.dylib 0x000000010dce9b17 _dispatch_worker_thread3 + 111 17 libsystem_pthread.dylib 0x000000010e06b637 _pthread_wqthread + 729 18 libsystem_pthread.dylib 0x000000010e06940d start_wqthread + 13 ) libc++abi.dylib: terminating with uncaught exception of type NSException


Solution

  • Please put exception breakpoint and run in debug mode to stop at the exact line of crash.

    Clearly you are trying to access objects from an empty array which is bound to crash. It is always advisable to put a check on array size before accessing its elements.

    enter image description here