0
votes

I have a line of code that keeps crashing

NSArray* address = [NSArray arrayWithArray:[[[access.filteredResults objectAtIndex:[indexPath row]] addressArray] objectAtIndex:0]];

I debugged it and I discovered that addressArray is the culprit.

It's defined in a class called ABContact (created by Erica Sadun, author of Developer Cookbook)

@property (nonatomic, readonly) NSArray *addressArray;

The implementation file has

- (NSArray *) addressArray {return [self arrayForProperty:kABPersonAddressProperty];}

The error message that I get is

    -[__NSCFDictionary getObjects:range:]: unrecognized selector sent to instance 0x18aeb0
    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary getObjects:range:]: unrecognized selector sent to instance 0x18aeb0'
    *** Call stack at first throw:
(
 0   CoreFoundation                      0x3284b987 __exceptionPreprocess + 114
 1   libobjc.A.dylib                     0x31aca49d objc_exception_throw + 24
 2   CoreFoundation                      0x3284d133 -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
 3   CoreFoundation                      0x327f4aa9 ___forwarding___ + 508
 4   CoreFoundation                      0x327f4860 _CF_forwarding_prep_0 + 48
 5   CoreFoundation                      0x327dc325 -[NSArray initWithArray:range:copyItems:] + 372
 6   CoreFoundation                      0x327e94d3 +[NSArray arrayWithArray:] + 62
 7   ContactMapper                       0x00003c17 -[RootViewController tableView:cellForRowAtIndexPath:] + 1110
 8   UIKit                               0x32c46a21 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 516
 9   UIKit                               0x32c467f3 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 34
 10  UIKit                               0x32c44d2d -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 936
 11  UIKit                               0x32c43edd -[UITableView layoutSubviews] + 140
 12  UIKit                               0x32bf00cf -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 26
 13  CoreFoundation                      0x327e9bbf -[NSObject(NSObject) performSelector:withObject:] + 22
 14  QuartzCore                          0x3087b685 -[CALayer layoutSublayers] + 120
 15  QuartzCore                          0x3087b43d CALayerLayoutIfNeeded + 184
 16  QuartzCore                          0x3089e593 -[CALayer(CALayerPrivate) layoutBelowIfNeeded] + 18
 17  UIKit                               0x32c1c3f3 -[UIView(Hierarchy) layoutBelowIfNeeded] + 22
 18  UIKit                               0x32e41cb3 -[UISplitViewController willRotateToInterfaceOrientation:duration:] + 614
 19  UIKit                               0x32cadc71 -[UIViewController window:willRotateToInterfaceOrientation:duration:] + 540
 20  UIKit                               0x32ced6b3 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 1158
 21  UIKit                               0x32caef5f -[UIWindow _setRotatableViewOrientation:duration:force:] + 54
 22  UIKit                               0x32c27007 -[UIWindow _updateToInterfaceOrientation:duration:force:] + 74
 23  UIKit                               0x32c26f81 -[UIWindow _updateInterfaceOrientationFromDeviceOrientation:] + 112
 24  UIKit                               0x32c26ead -[UIWindow _handleDeviceOrientationChange:] + 88
 25  Foundation                          0x320f1623 _nsnote_callback + 142
 26  CoreFoundation                      0x327d2123 __CFXNotificationPost_old + 402
 27  CoreFoundation                      0x327d1dc3 _CFXNotificationPostNotification + 118
 28  Foundation                          0x320e0d23 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
 29  UIKit                               0x32bf0819 -[UIDevice setOrientation:animated:] + 144
 30  UIKit                               0x32c152ff -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 438
 31  UIKit                               0x32be148b -[UIApplication handleEvent:withNewEvent:] + 1114
 32  UIKit                               0x32be0ec9 -[UIApplication sendEvent:] + 44
 33  UIKit                               0x32be0907 _UIApplicationHandleEvent + 5090
 34  GraphicsServices                    0x3094af03 PurpleEventCallback + 666
 35  CoreFoundation                      0x327e06ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
 36  CoreFoundation                      0x327e06c3 __CFRunLoopDoSource1 + 166
 37  CoreFoundation                      0x327d2f7d __CFRunLoopRun + 520
 38  CoreFoundation                      0x327d2c87 CFRunLoopRunSpecific + 230
 39  CoreFoundation                      0x327d2b8f CFRunLoopRunInMode + 58
 40  UIKit                               0x32c14309 -[UIApplication _run] + 380
 41  UIKit                               0x32c11e93 UIApplicationMain + 670
 42  ContactMapper                       0x00002b67 main + 70
 43  ContactMapper                       0x00002b1c start + 40

I'm not sure how to fix it?

access.filteredResults is an NSArray

It might be how AddressBook data is handled (CFDictionary vs NSArray or NSDictionary). I've spent 15 hours and I'm stuck. Any help would be appreciated.

1

1 Answers

2
votes

Nope. NSCFDictionary has nothing to do with your problem.

Your problem is that you have under-retained or over-released an array object, and that object died, and another object (in this case, it was a dictionary, but it could have been anything) got allocated at the same address. Your code is trying to create an array with the old object, but ends up passing the dictionary that has succeeded it instead.

You need to find out where you are unduly releasing or failing to retain the value of addressArray.

It may help to run your app under the Zombies instrument, whose very purpose is debugging an application that prematurely releases or fails to retain an object.