I’m developing my first application and it has come to a time to test it on a real device. I had an old iPhone 3GS in the office that I updated to the latest version of IOS.
When I try to launch the application on the iPhone simulator, everything works well. But then, I try to launch it on my device, and the application crashes with the error below :
2012-09-13 14:16:01.556 MyFirstApp[1702:707] *** Terminating app due to uncaught
exception 'NSUnknownKeyException', reason: '[<__NSCFString 0x15e2e0> valueForUndefinedKey:]:
this class is not key value coding-compliant for the key testKey.'
I checked my build settings, which are as below :

I’ve also heard that it can come from some variables that are not properly set or deleted in IB, but I don’t have any warnings about that…
Here’s some code I’m using on the view concerned by the error :
@implementation HomeViewController {
@private
NSArray *_orders;
__strong UIActivityIndicatorView *_activityIndicatorView;
}
@synthesize orderList = _orderList;
- (void)reload:(id)sender {
[_activityIndicatorView startAnimating];
[Order orderListWithBlock:^(NSArray *orders) {
if (orders) {
_orders = orders;
[self.orderList reloadData];
}
[_activityIndicatorView stopAnimating];
}];
}
- (void)viewDidLoad
{
[self reload:nil];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Custom Cell Segment";
static NSString *OtherCellIdentifier = @"Other Cell Segment";
Order *o = [_orders objectAtIndex:indexPath.row];
if ([o.testKey isEqualToString:@""]) {
[SOME STUFF]
}
else {
[SOME OTHER STUFF]
}
}
Does anyone knows where does the error can come from ?
Thanks for your help !
That may not be because of the simulator vs. device, but because you had an old IBOutlet in Interface Builder that you deleted since, but the connection is still present in the XIB. Just open the XIB where you have that old IBOutlet “testKey” connection and remove the connection.
Now for why your app worked on your simulator so far, this is because the XIB hasn’t been recompiled, or some old XIB that you deleted from the sources are still in the build product from a previous build.
So I bet that if you completely clean your project, removing the Build Directory and rebuilding from the beginning, you will have the same problem in the Simulator and can thus reproduce it and debug it.
To do that, you may perform a “Clean” from the “Product” menu, or even better old the option key while opening this menu to select “Clean Build Folder…”.
Sometimes it is not sufficient anyway, so you may instead delete the whole build folder from the Finder:
This will delete your Build Output directory so that the next time you build your project it will recompile everything from scratch.
From there you may see your warning on the XIB file and you will observe that your application will also crash in the Simulator, meaning that is not a crash that is due to the device, but due to the fact that previous builds messed up your built application.
And you can fix this crash (by removing the old “testKey” outlet connection in the XIB) for both device and simulator.