How to understand this crash? - objective-c

Crash report:
0 ??? 0x0 + 0
1 TestPrj -[AppListReader addInstalledApps:] (AppListReader.m:186) + 77516
2 TestPrj -[AppListReader getAppsInstalled] (AppListReader.m:161) + 77320
3 TestPrj -[DetectAppsInstalledService activate:] (DetectAppsInstalledService.m:48) + 197612
4 TestPrj -[BusinessManager handleBG] (BusinessManager.m:762) + 116672
5 TestPrj -[BusinessManager activate:] (BusinessManager.m:208) + 106236
6 TestPrj -[AppDelegate launchViewController:] (AppDelegate.m:338) + 32564
7 TestPrj -[AppDelegate application:didFinishLaunchingWithOptions:] (AppDelegate.m:153) + 27396
8 UIKit <redacted> + 316
9 UIKit <redacted> + 1564
10 UIKit <redacted> + 772
11 UIKit <redacted> + 3316
12 UIKit <redacted> + 104
13 UIKit <redacted> + 672
14 GraphicsServices <redacted> + 676
15 GraphicsServices <redacted> + 48
16 CoreFoundation <redacted> + 56
17 CoreFoundation <redacted> + 444
18 CoreFoundation <redacted> + 1620
19 CoreFoundation CFRunLoopRunSpecific + 452
20 UIKit <redacted> + 784
21 UIKit UIApplicationMain + 1156
22 TestPrj main (main.m:21) + 23548
23 libdyld.dylib <redacted> + 4
Line 186 is:
NSMutableArray *allObjetcsArr = [self getInstalled];
This is implementation:
-(NSMutableArray *)getInstalled
{
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:#"ApplicationType",#"Any", [self defaultReturnAttributes] ,#"ReturnAttributes",nil];
MobileInstallationLookup = dlsym(RTLD_DEFAULT, "MobileInstallationLookup");
NSDictionary *apps = (__bridge NSDictionary *)((__bridge void*)MobileInstallationLookup(options));
NSMutableArray *allObjetcsArr = [[NSMutableArray alloc]initWithArray:[apps allValues]];
return allObjetcsArr;
}
Crash is received via BugSense and I am not able to reproduce it. I think it is related to MobileInstallationLookup framework (which is private api) but I am not sure.
It is not clear for me, why
-(NSMutableArray *)getInstalled
Is not present in stack trace, only ??? 0x0 + 0

My money is on these lines:
MobileInstallationLookup = dlsym(RTLD_DEFAULT, "MobileInstallationLookup");
NSDictionary *apps = (__bridge NSDictionary *)((__bridge void*)MobileInstallationLookup(options));
MobileInstallationLookup is obviously a global, but it's not clear why; for example if it's global they why is it being re-assigned in this method and why does the variable start with a capital letter (which is unconventional)?
There is no check to ensure that dlsym() succeeded, and dereferencing a null pointer would cause the crash you are getting.

Related

Application Crash on ios11 & Xcode 9: while adding [self addChildViewController:]

While adding child viewcontroller, I am getting following crash,
Here NavigationViewController is extended from UIViewController.
This error is coming when I upgraded to Xcode 9, working successfully on earlier versions of Xcode.
I referred the Link but not getting any satisfied answer, please help me out this,
Thanx in advance. :)
The block of code is:
_mainSectionsController = [[[MainSectionsController alloc] initWithNibName:nil bundle:nil] autorelease];
[self addChildViewController:_mainSectionsController];
**Init method of _mainSectionsController** .
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (!self) return nil;
self.edgesForExtendedLayout = UIRectEdgeAll;
self.viewControllers = #
[
[[[NavigationViewController alloc] initWithNibName:nil bundle:nil]
autorelease]
];
return self;
}
**init method of NavigationViewController**
-(id)initWithNibName:(NSString*)nibNameOrNil bundle: (NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (!self) return nil;
self.edgesForExtendedLayout = UIRectEdgeAll;
_navController = [[[UINavigationController alloc] initWithNibName:nil bundle:nil] autorelease];
_navController.get().delegate = self;
_navController.get().navigationBarHidden = YES;
_navController.get().view.clipsToBounds = YES;
_navController.get().view.backgroundColor = [UIColor clearColor];
return self;
}
2018-05-22 10:46:23.112290+0530 [912:19925] -[NavigationViewController _viewControllerSubtreeDidGainViewController:]: unrecognized selector sent to instance 0x7f91ba83c000
2018-05-22 10:46:24.939903+0530 [912:19925] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NavigationViewController _viewControllerSubtreeDidGainViewController:]: unrecognized selector sent to instance 0x7f91ba83c000'
* First throw call stack:
(
0 CoreFoundation 0x000000010f03f12b exceptionPreprocess + 171 .
1 libobjc.A.dylib 0x000000010e640f41 objc_exception_throw + 48
2 CoreFoundation 0x000000010f0c0024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKit 0x000000010b2cdf51 -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x000000010efc1f78 ___forwarding_ + 1432
5 CoreFoundation 0x000000010efc1958 _CF_forwarding_prep_0 + 120
6 UIKit 0x000000010b246c1d -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:] + 696
7 UIKit 0x000000010b26930e -[UIViewController(UIContainerViewControllerProtectedMethods) addChildViewController:] + 83
8 0x00000001058eeac3 -[MainViewController initWithNibName:bundle:] + 5235
9 0x00000001059876ca -[AppDelegate loadMainViewController] + 122
10 0x0000000105984561 -[AppDelegate application:didFinishLaunchingWithOptions:] + 1137
11 UIKit 0x000000010b091bca -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 299
12 UIKit 0x000000010b093648 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4113
13 UIKit 0x000000010b098aeb -[UIApplication _runWithMainScene:transitionContext:completion:] + 1720
14 UIKit 0x000000010b4626f8 111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 924
15 UIKit 0x000000010b8384c8 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
16 UIKit 0x000000010b4622f1 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 249
17 UIKit 0x000000010b462b6b -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 696
18 UIKit 0x000000010bde0a69 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 262
19 UIKit 0x000000010bde0922 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 444
20 UIKit 0x000000010babd9c8 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 221
21 UIKit 0x000000010bcbcb06 _performActionsWithDelayForTransitionContext + 100
22 UIKit 0x000000010babd88b -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 231
23 UIKit 0x000000010b837b25 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
24 UIKit 0x000000010b09736a -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 523
25 UIKit 0x000000010b672605 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 369
26 FrontBoardServices 0x0000000116cb8cc0 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 338
27 FrontBoardServices 0x0000000116cc17b5 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 235
28 libdispatch.dylib 0x000000010f87b33d _dispatch_client_callout + 8
29 libdispatch.dylib 0x000000010f8809f3 _dispatch_block_invoke_direct + 592
30 FrontBoardServices 0x0000000116ced498 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24
31 FrontBoardServices 0x0000000116ced14e -[FBSSerialQueue _performNext] + 464
32 FrontBoardServices 0x0000000116ced6bd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
33 CoreFoundation 0x000000010efe2101 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
34 CoreFoundation 0x000000010f081f71 __CFRunLoopDoSource0 + 81
35 CoreFoundation 0x000000010efc6a19 __CFRunLoopDoSources0 + 185
36 CoreFoundation 0x000000010efc5fff __CFRunLoopRun + 1279
37 CoreFoundation 0x000000010efc5889 CFRunLoopRunSpecific + 409
38 GraphicsServices 0x000000010fed99c6 GSEventRunModal + 62
39 UIKit 0x000000010b09a5d6 UIApplicationMain + 159
40 0x000000010590c331 main + 65
41 libdyld.dylib 0x000000010f8f7d81 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Since you have autorelease in your MainSectionsController code I assume that you don't use ARC there. I highly recommend upgrading the code of MainSectionsController and NavigationViewController to ARC. This prevents accidental overreleases that might cause issues like this one.
In addition I'd recommend to move self.viewControllers assignment from the constructor to viewDidLoad if possible.

Why would iOS try to call rangeOfCharacterFromSet: on an NSIndexPath?

I'm getting the following error, which causes a SIGABRT:
2015-09-10 17:54:23.859 MyApp[1310:2027719] ERROR CRASH #(null) -[NSIndexPath rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0xc000000000000016
2015-09-10 17:54:23.879 MyApp[1310:2027719] ERROR Stack Trace: (
0 CoreFoundation 0x0000000183840248 <redacted> + 160
1 libobjc.A.dylib 0x00000001952640e4 objc_exception_throw + 60
2 CoreFoundation 0x00000001838472f4 <redacted> + 0
3 CoreFoundation 0x00000001838440a8 <redacted> + 928
4 CoreFoundation 0x000000018374696c _CF_forwarding_prep_0 + 92
5 UIKit 0x0000000188632a44 <redacted> + 104
6 UIKit 0x00000001887a0ff0 <redacted> + 76
7 UIKit 0x00000001887a10b0 <redacted> + 56
8 UIKit 0x00000001887a1194 <redacted> + 36
9 QuartzCore 0x0000000187bf0820 <redacted> + 320
10 QuartzCore 0x0000000187bf06c4 <redacted> + 32
11 QuartzCore 0x0000000187befe58 <redacted> + 276
12 QuartzCore 0x0000000187befbd8 <redacted> + 528
13 QuartzCore 0x0000000187be9300 <redacted> + 80
14 CoreFoundation 0x00000001837f7ff0 <redacted> + 32
15 CoreFoundation 0x00000001837f4f7c <redacted> + 360
16 CoreFoundation 0x00000001837f535c <redacted> + 836
17 CoreFoundation 0x0000000183720f74 CFRunLoopRunSpecific + 396
18 GraphicsServices 0x000000018d0436fc GSEventRunModal + 168
19 UIKit 0x0000000188322d94 UIApplicationMain + 1488
20 MyApp 0x00000001000437b0 main + 68
21 libdyld.dylib 0x000000019590ea08 <redacted> + 4
which looks like iOS is trying to send a message to an NSString selector, but the message was sent to an NSIndexPath. Weird!
I've since found the problem; I'd set the value of the text in a UILabel to be a pointer to an object in a CoreData object's NSNumber column (0xc000000000000016) instead of an NSString. My fix was added .intValue to the NSNumber before passing it to my enumToString: method.
typedef NS_ENUM(NSInteger, MyEnum)
{
MyEnum1 = 1,
MyEnum2,
MyEnum3
};
- (NSString*)enumToString:(MyEnum)enumValue
{
switch (enumValue) {
case MyEnum1:
return #"One";
case MyEnum2:
return #"Two";
case MyEnum3:
return #"Three";
}
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MyCell"];
// cdObject is a managed object in CoreData. Its enumValue column is an NSNumber.
cell.textLabel.text = [self enumToString:cdObject.enumValue];
return cell;
}
This just leaves the question: Why would this cause iOS to try to send a message to the non-existant selector -[NSIndexPath rangeOfCharacterFromSet:]?
The crash occurred just after completing a -[UITableViewDataSource tableView:cellForRowAtIndexPath:]
Ok, so the cause is most likely not some threading gone wrong. Core Data turns the NSManagedObjects into faults at some point. This might be related. Also, NSNumbers are kind of special objects: the pointer is a tagged pointer, and this tagged pointer might contain the actual numeric value. This might also be related. In any case, a message was sent to a pointer, and that pointer no longer points to an object that recognizes that message. Read here about tagged pointers: https://www.mikeash.com/pyblog/friday-qa-2012-07-27-lets-build-tagged-pointers.html

Why does [NSTextStorage setAttributedString] crash with NSMutableAttributedString?

When I run the following Code it crashes at the last line. I don't have any idea why. This function gets called in awakeFromNib.
- (void)setMotdText:(NSString *)text
{
NSString *boldFontName = [[NSFont boldSystemFontOfSize:12] fontName];
NSMutableAttributedString *attrstr = [[NSMutableAttributedString alloc] initWithString:text];
[attrstr beginEditing];
[attrstr addAttribute:NSFontAttributeName value:boldFontName range:NSMakeRange(0, 16)];
[attrstr endEditing];
[self.motdTextView.textStorage setAttributedString:attrstr];
}
I get this crash log:
2012-06-22 11:32:22.348 MSM-Plan[20785:403] -[__NSCFConstantString _isDefaultFace]: unrecognized selector sent to instance 0x7fff79b9f380
2012-06-22 11:32:22.349 MSM-Plan[20785:403] An uncaught exception was raised
2012-06-22 11:32:22.349 MSM-Plan[20785:403] -[__NSCFConstantString _isDefaultFace]: unrecognized selector sent to instance 0x7fff79b9f380
2012-06-22 11:32:22.351 MSM-Plan[20785:403] (
0 CoreFoundation 0x00007fff8a5bef56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8ae19d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8a64b1be -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff8a5abe23 ___forwarding___ + 371
4 CoreFoundation 0x00007fff8a5abc38 _CF_forwarding_prep_0 + 232
5 AppKit 0x00007fff8e0b060c -[NSMutableAttributedString(NSMutableAttributedStringKitAdditions) fixFontAttributeInRange:] + 1249
6 AppKit 0x00007fff8e0afeb7 -[NSMutableAttributedString(NSMutableAttributedStringKitAdditions) fixAttributesInRange:] + 64
7 AppKit 0x00007fff8e19b521 -[NSTextStorage processEditing] + 107
8 AppKit 0x00007fff8e0c2564 -[NSTextStorage edited:range:changeInLength:] + 385
9 Foundation 0x00007fff8d6f4497 -[NSConcreteMutableAttributedString replaceCharactersInRange:withAttributedString:] + 328
10 AppKit 0x00007fff8e1dfd19 -[NSConcreteTextStorage replaceCharactersInRange:withAttributedString:] + 81
11 MSM-Plan 0x000000010206af5a -[MSM_PlanAppDelegate setMotdText:] + 314
12 MSM-Plan 0x000000010206c455 -[MSM_PlanAppDelegate awakeFromNib] + 1701
13 CoreFoundation 0x00007fff8a5b5fb1 -[NSObject performSelector:] + 49
14 CoreFoundation 0x00007fff8a5b5f32 -[NSSet makeObjectsPerformSelector:] + 274
15 AppKit 0x00007fff8e0369ff -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1245
16 AppKit 0x00007fff8e02cf73 loadNib + 322
17 AppKit 0x00007fff8e02c470 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 217
18 AppKit 0x00007fff8e02c38b +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 141
19 AppKit 0x00007fff8e02c2ce +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 364
20 AppKit 0x00007fff8e29d06f NSApplicationMain + 398
21 MSM-Plan 0x000000010206adf2 main + 34
22 MSM-Plan 0x000000010206adc4 start + 52
)
2012-06-22 11:32:22.416 MSM-Plan[20785:403] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString _isDefaultFace]: unrecognized selector sent to instance 0x7fff79b9f380'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff8a5bef56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8ae19d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8a64b1be -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff8a5abe23 ___forwarding___ + 371
4 CoreFoundation 0x00007fff8a5abc38 _CF_forwarding_prep_0 + 232
5 AppKit 0x00007fff8e0b060c -[NSMutableAttributedString(NSMutableAttributedStringKitAdditions) fixFontAttributeInRange:] + 1249
6 AppKit 0x00007fff8e0afeb7 -[NSMutableAttributedString(NSMutableAttributedStringKitAdditions) fixAttributesInRange:] + 64
7 AppKit 0x00007fff8e19b521 -[NSTextStorage processEditing] + 107
8 AppKit 0x00007fff8e0c2564 -[NSTextStorage edited:range:changeInLength:] + 385
9 Foundation 0x00007fff8d6f4497 -[NSConcreteMutableAttributedString replaceCharactersInRange:withAttributedString:] + 328
10 AppKit 0x00007fff8e1dfd19 -[NSConcreteTextStorage replaceCharactersInRange:withAttributedString:] + 81
11 MSM-Plan 0x000000010206af5a -[MSM_PlanAppDelegate setMotdText:] + 314
12 MSM-Plan 0x000000010206c455 -[MSM_PlanAppDelegate awakeFromNib] + 1701
13 CoreFoundation 0x00007fff8a5b5fb1 -[NSObject performSelector:] + 49
14 CoreFoundation 0x00007fff8a5b5f32 -[NSSet makeObjectsPerformSelector:] + 274
15 AppKit 0x00007fff8e0369ff -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1245
16 AppKit 0x00007fff8e02cf73 loadNib + 322
17 AppKit 0x00007fff8e02c470 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 217
18 AppKit 0x00007fff8e02c38b +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 141
19 AppKit 0x00007fff8e02c2ce +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 364
20 AppKit 0x00007fff8e29d06f NSApplicationMain + 398
21 MSM-Plan 0x000000010206adf2 main + 34
22 MSM-Plan 0x000000010206adc4 start + 52
)
terminate called throwing an exception(lldb)
Has anybody an idea? If I call it with a NSAttributedString-Object thereĀ“s no error.
I had to change the first line to:
NSFont *boldFont = [NSFont boldSystemFontOfSize:12];
Now it works, because the value attribute requires a NSFont-Object and not a NSString with the fonts name.
This is the working Code:
- (void)setMotdText:(NSString *)text
{
NSFont *boldFont = [NSFont boldSystemFontOfSize:12];
NSMutableAttributedString *attrstr = [[NSMutableAttributedString alloc] initWithString:text];
[attrstr beginEditing];
[attrstr addAttribute:NSFontAttributeName value:boldFont range:NSMakeRange(0, 16)];
[attrstr endEditing];
[self.motdTextView.textStorage setAttributedString:attrstr];
}

Why am I getting invalidArgument exception while running unit test?

Inside my Table view controller I have following method
-(BOOL)isValidCoordinate:(CLLocationCoordinate2D)coordinate
{
//This is just to make sure exception is always thrown a cut down version of method
[NSException raise:#"Invalid longitude value" format:#"Longitude of %d is invalid", coordinate.longitude];
return TRUE;
}
I am running a unit test against it and I it failing giving following exception
2011-10-04 22:58:43.380 navman2[74159:ec03] -[MapViewController isValidCoordinate:]: unrecognized selector sent to instance 0x5e20830
2011-10-04 22:58:43.382 navman2[74159:ec03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MapViewController isValidCoordinate:]: unrecognized selector sent to instance 0x5e20830'
*** Call stack at first throw:
(
0 CoreFoundation 0x00f555a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x010a9313 objc_exception_throw + 44
2 CoreFoundation 0x00f570bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00ec6966 ___forwarding___ + 966
4 CoreFoundation 0x00ec6522 _CF_forwarding_prep_0 + 50
5 navman2Tests 0x05765b41 -[navman2Tests testExceptionThrownBycoordinatesCheck] + 193
6 CoreFoundation 0x00ec5c7d __invoking___ + 29
7 CoreFoundation 0x00ec5b51 -[NSInvocation invoke] + 145
8 SenTestingKit 0x201043d2 -[SenTestCase invokeTest] + 69
9 SenTestingKit 0x20104aa7 -[SenTestCase performTest:] + 192
10 SenTestingKit 0x201041d3 -[SenTest run] + 88
11 SenTestingKit 0x20106eda -[SenTestSuite performTest:] + 115
12 SenTestingKit 0x201041d3 -[SenTest run] + 88
13 SenTestingKit 0x20106eda -[SenTestSuite performTest:] + 115
14 SenTestingKit 0x201041d3 -[SenTest run] + 88
15 SenTestingKit 0x20106eda -[SenTestSuite performTest:] + 115
16 SenTestingKit 0x201041d3 -[SenTest run] + 88
17 SenTestingKit 0x201067a4 +[SenTestProbe runTests:] + 174
18 Foundation 0x0092e79e __NSFireDelayedPerform + 441
19 CoreFoundation 0x00f368c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
20 CoreFoundation 0x00f37e74 __CFRunLoopDoTimer + 1220
21 CoreFoundation 0x00e942c9 __CFRunLoopRun + 1817
22 CoreFoundation 0x00e93840 CFRunLoopRunSpecific + 208
23 CoreFoundation 0x00e93761 CFRunLoopRunInMode + 97
24 GraphicsServices 0x016171c4 GSEventRunModal + 217
25 GraphicsServices 0x01617289 GSEventRun + 115
26 UIKit 0x001b5c93 UIApplicationMain + 1160
27 navman2 0x000028b9 main + 121
28 navman2 0x00002835 start + 53
)
terminate called throwing an exception(gdb)
Unit test is following:
#import "navman2Tests.h"
#import "TableViewController.h"
#import "MapViewController.h"
#implementation navman2Tests
- (void)setUp
{
[super setUp];
// Set-up czode here.
}
- (void)tearDown
{
// Tear-down code here.
[super tearDown];
}
- (void) testExceptionThrownBycoordinatesCheck
{
TableViewController *newView2 =[[MapViewController alloc] init];
CLLocationCoordinate2D coordinate;
double lat = 61.2180556;
double lng = -149.9002778;
coordinate.latitude = lat;
coordinate.longitude = lng;
STAssertThrows([newView2 isValidCoordinate:coordinate],#"some text description");
[newView2 release];
}
#end
The error is that you did declare newView2 as a TableViewController not a MapViewController (which has that method), change:
TableViewController *newView2 =[[MapViewController alloc] init];
with:
MapViewController *newView2 =[[MapViewController alloc] init];
anyway I would call the variable newViewController rather than newView2 :P

can someone please explain why this keeps crashing on iOS 4.2?

The code worked in iOS 3.2 and in 4.2 it keeps crashing.
Here's the line that it crashes on.
NSArray* address = [NSArray arrayWithArray:[[[access.filteredResults objectAtIndex:[indexPath row]] addressArray] objectAtIndex:0]];
2010-11-04 12:20:03.060 ContactMapper[2211:207] -[__NSCFDictionary getObjects:range:]: unrecognized selector sent to instance 0x5648e30
2010-11-04 12:20:03.062 ContactMapper[2211:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary getObjects:range:]: unrecognized selector sent to instance 0x5648e30'
*** Call stack at first throw:
(
0 CoreFoundation 0x0117abe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x012cf5c2 objc_exception_throw + 47
2 CoreFoundation 0x0117c6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x010ec366 ___forwarding___ + 966
4 CoreFoundation 0x010ebf22 _CF_forwarding_prep_0 + 50
5 CoreFoundation 0x01176605 -[NSArray initWithArray:range:copyItems:] + 245
6 CoreFoundation 0x010e1367 +[NSArray arrayWithArray:] + 119
7 ContactMapper 0x00003a8d -[RootViewController tableView:cellForRowAtIndexPath:] + 1333
8 UIKit 0x0033a7fa -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
9 UIKit 0x0033077f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
10 UIKit 0x00345450 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
11 UIKit 0x0033d538 -[UITableView layoutSubviews] + 242
12 QuartzCore 0x01fc2451 -[CALayer layoutSublayers] + 181
13 QuartzCore 0x01fc217c CALayerLayoutIfNeeded + 220
14 UIKit 0x005c7702 -[UISplitViewController willRotateToInterfaceOrientation:duration:] + 1134
15 UIKit 0x00373df2 -[UIViewController window:willRotateToInterfaceOrientation:duration:] + 962
16 UIKit 0x002edee5 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 1783
17 UIKit 0x002e8538 -[UIWindow _setRotatableViewOrientation:duration:force:] + 89
18 UIKit 0x002eb643 -[UIWindow _updateInterfaceOrientationFromDeviceOrientation:] + 164
19 Foundation 0x000306c1 _nsnote_callback + 145
20 CoreFoundation 0x01152f99 __CFXNotificationPost_old + 745
21 CoreFoundation 0x010d233a _CFXNotificationPostNotification + 186
22 Foundation 0x00026266 -[NSNotificationCenter postNotificationName:object:userInfo:] + 134
23 UIKit 0x00477d0a -[UIDevice setOrientation:animated:] + 228
24 UIKit 0x002c9637 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 656
25 UIKit 0x002d3db2 -[UIApplication handleEvent:withNewEvent:] + 1533
26 UIKit 0x002cc202 -[UIApplication sendEvent:] + 71
27 UIKit 0x002d1732 _UIApplicationHandleEvent + 7576
28 GraphicsServices 0x01ab0a36 PurpleEventCallback + 1550
29 CoreFoundation 0x0115c064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
30 CoreFoundation 0x010bc6f7 __CFRunLoopDoSource1 + 215
31 CoreFoundation 0x010b9983 __CFRunLoopRun + 979
32 CoreFoundation 0x010b9240 CFRunLoopRunSpecific + 208
33 CoreFoundation 0x010b9161 CFRunLoopRunInMode + 97
34 UIKit 0x002c8fa8 -[UIApplication _run] + 636
35 UIKit 0x002d542e UIApplicationMain + 1160
36 ContactMapper 0x00002638 main + 102
37 ContactMapper 0x000025c9 start + 53
)
terminate called after throwing an instance of 'NSException'
At first glance, this line is your problem:
[NSArray initWithArray:range:copyItems:]
at first glance, it might be that you need indexPath.row not [indexPath row].
Because iOS 4.2 is still under NDA, we cannot talk about 4.2-specific code.
We can however, talk about 4.1 and previous.
First, you're going to go to the 4.2 diffs page after you sign into the iOS Dev Center. This will tell you what's changed in that release. Since these pages only show release to release, look at the 3.2-4.0 diffs, 4.0-4.1 and 4.1-4.2 diffs. You are looking for a change in the API for UITableView or NSArray that obviously cannot be talked about here.
Second, you're going to download the WWDC '10 session on crash reports. It's a little tedious but the hour spent learning about how to read a crash report is WELL worth it.
Hope this helps!
The error you're getting tells you that the selector getObjects:range: is being sent to an __NSCFDictionary. So clearly the following:
[[[access.filteredResults objectAtIndex:[indexPath row]] addressArray] objectAtIndex:0]
... used to return an NSArray, but is now returning an NSDictionary.
I don't know what access is so I have no idea what else to say other than you can change the line you cited as the source of the error to:
NSDictionary* address = [NSDictionary dictionaryWithDictionary:[[[access.filteredResults objectAtIndex:[indexPath row]] addressArray] objectAtIndex:0]];
Once you've done that, whatever code follows that uses address clearly needs to also change to deal with the fact that you're no longer accessing an array.
You need the new iOS CookBook code