Matt Douhan Matt Douhan - 14 days ago 6
iOS Question

prepareForSegue crashes when assigning NSManagedObject but why?

I am using the follwing code to send data from one a UITableViewController to a UIViewController but it crashes for some reason that I dont understand why, there are no NIL/NULL values involved. please help me explain what causes the crash.

This is the code in question

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"updateItem"]) {
NSManagedObject *selectedItem = [self.pimItems objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
PimItemDetailView *destViewController = segue.destinationViewController;
if([NWTillHelper isDebug] == 1) {
NSLog(@"PimItemListView:prepareForSegue:selectedItem holds %@", selectedItem);
NSLog(@"PimItemListView:prepareForSegue:destViewController holds %@", destViewController);
}
destViewController.pimItem = selectedItem;
}
}


it crashes on exactly this row

destViewController.pimItem = selectedItem;


The debugs tells me I am not having any NIL/NULL values

2016-11-22 18:47:05.043 NWMobileTill[836:10726] PimItemListView:prepareForSegue:selectedItem holds <TillData: 0x6080002c3bf0> (entity: TillData; id: 0xd0000000000c0002 <x-coredata:/
colorCode = 95;
companyId = "BE_HM";
discountable = 1;
exchangeable = 1;
itemId = 101064025138012;
languageCode = eng;
noos14 = "09258385254957,09258389874953";
sizeCode = "163-012";
status = 1;
taxGroup = 1;
taxRegion = BE;
tradeItemDesc = "Jersey basic";
withTax = 1;
})
2016-11-22 18:47:05.043 NWMobileTill[836:10726] PimItemListView:prepareForSegue:destViewController holds <PimItemDetailView: 0x7f81a1e48050>

The entire crash message is as follows, any help much appreciated.

2016-11-22 18:47:05.064 NWMobileTill[836:10726] -[__NSCFNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0xb000000000000011
2016-11-22 18:47:05.074 NWMobileTill[836:10726] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0xb000000000000011'
*** First throw call stack:
(
0 CoreFoundation 0x000000010167234b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000100cb621e objc_exception_throw + 48
2 CoreFoundation 0x00000001016e1f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00000001015f7c15 ___forwarding___ + 1013
4 CoreFoundation 0x00000001015f7798 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001025b37c7 -[UITextField _textNeedsSanitizing:] + 184
6 UIKit 0x00000001025b34d8 -[UITextField setText:] + 61
7 NWMobileTill 0x00000001006a345e -[PimItemDetailView viewDidLoad] + 1486
8 UIKit 0x0000000101c36c99 -[UIViewController loadViewIfRequired] + 1258
9 UIKit 0x0000000101c370cc -[UIViewController view] + 27
10 UIKit 0x00000001024fb49c -[_UIFullscreenPresentationController _setPresentedViewController:] + 87
11 UIKit 0x0000000101c11932 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 141
12 UIKit 0x0000000101c49f37 -[UIViewController _presentViewController:withAnimationController:completion:] + 3956
13 UIKit 0x0000000101c4d30b -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 530
14 UIKit 0x0000000101c4cdf1 -[UIViewController presentViewController:animated:completion:] + 179
15 UIKit 0x00000001022604f7 __74-[UIStoryboardPresentationSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 133
16 UIKit 0x000000010226ffbd -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 447
17 UIKit 0x000000010226fdcd -[UIStoryboardSegueTemplate _perform:] + 82
18 UIKit 0x000000010227008f -[UIStoryboardSegueTemplate perform:] + 156
19 UIKit 0x0000000101bec52a -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1769
20 UIKit 0x0000000101bec78d -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 330
21 UIKit 0x0000000101aa22eb _runAfterCACommitDeferredBlocks + 320
22 UIKit 0x0000000101a8ef6f _cleanUpAfterCAFlushAndRunDeferredBlocks + 566
23 UIKit 0x0000000101ac03da _afterCACommitHandler + 176
24 CoreFoundation 0x0000000101616e17 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
25 CoreFoundation 0x0000000101616d87 __CFRunLoopDoObservers + 391
26 CoreFoundation 0x00000001015fb4b6 CFRunLoopRunSpecific + 454
27 GraphicsServices 0x0000000105922a6f GSEventRunModal + 161
28 UIKit 0x0000000101a95964 UIApplicationMain + 159
29 NWMobileTill 0x00000001006a580f main + 111
30 libdyld.dylib 0x000000010383d68d start + 1
31 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Answer

I'm no expert but would start here :

0x00000001025b37c7 -[UITextField _textNeedsSanitizing:] + 184 6 UIKit 0x00000001025b34d8 -[UITextField setText:] + 61 7 NWMobileTill 0x00000001006a345e -[PimItemDetailView viewDidLoad] + 1486

Look at the viewDidLoad method and see whats happening inside there , It might be trying to assign a variable (Set a UITextField or other) and is not managing to do it , either because of a nil/null value OR the field/property it's trying to set is actually missing on the object.

Again no expert- just a cursory glance tells me that's where I would start looking.