Application error during startup on valueForUndefinedKey error

I show the table view during application launch. Each row shows data for managed objects in some form. One client reports application startup failure. I looked at his crash log and was able to track down where I am using a method [NSManagedObject valueForKey:]

within a method cellForRowAtIndexPath

. The application crashes with an exception [NSManagedObject valueForUndefinedKey:]


Why can this only trigger one device in 1000's of devices? By running the same iOS version and app, I could not simulate it on any of my devices. what could have gone wrong?

Last Exception Backtrace:

0   CoreFoundation                  0x3549e88f __exceptionPreprocess + 163
1   libobjc.A.dylib                 0x368c5259 objc_exception_throw + 33
2   CoreFoundation                  0x3549e5c5 -[NSException init] + 1
3   CoreData                        0x329d3b23 -[NSManagedObject valueForUndefinedKey:] + 327
4   Foundation                      0x312b59d1 _NSGetUsingKeyValueGetter + 125
5   CoreData                        0x3298d995 -[NSManagedObject valueForKey:] + 121
6   MyApp                   0x0000c513 -[Activity isOn:] (Activity.m:371)
7   MyApp                   0x0000beaf -[Activity firstMarkableDate] (Activity.m:163)
8   MyApp                   0x0000c0cb -[Activity statusString] (Activity.m:220)
9   MyApp                   0x0000bd51 -[Activity statusColor] (Activity.m:139)
10  MyApp                   0x00004af1 -[ActivityListViewController tableView:cellForRowAtIndexPath:] (ActivityListViewController.m:418)
11  UIKit                           0x3251d0a3 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 547



source to share

1 answer

It could be a memory management issue. See -[Activity isOn:]

where it is calling valueForKey:

. The object you are sending valueForKey:

appears to be of the wrong class. See where the object is coming from.

An object can be reissued, and its memory address can be occupied by an object of another class that does not match the KVO for the key trackname

. In this case, I would bet your application gets EXC_BAD_ACCESS

even more often.

Why is this happening? NSManagedObjects

have a lot of subtleties regarding their lifetime. For example, they can be removed elsewhere in your application, so you should always expect this and act accordingly.

I hope this points you in the right direction.



All Articles