Simple document app, throwing an exception on "revert to saved" in Mac OS X 10.7 Lion - objective-c

I have a simple document app, based on the document template, which is throwing an exception when the "Revert to Saved -> Last Opened Version" menu item is selected on Mac OS X 10.7.
The exception isn't in my code, it's inside Cocoa. It also doesn't appear to be related to anything I'm doing. My app is very simple (at this stage), almost a vanilla cocoa document based app, based on the template included with the latest stable version of Xcode.
I realise this is probably a bug in Lion, but I need to find a workaround.
See below for the exception, and the entire contents (very small) of my NSDocument subclass.
Steps to reproduce
open any document
type a single character into the text view
select File -> Revert to Saved
click Last Opened Version
Exception
2011-09-04 07:10:29.182 myapp[15433:707] *** -[NSPathStore2 stringByAppendingPathExtension:]: nil argument
2011-09-04 07:10:29.191 myapp[15433:707] (
0 CoreFoundation 0x00007fff89c2b986 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff90c6ed5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff89c2b7ba +[NSException raise:format:arguments:] + 106
3 CoreFoundation 0x00007fff89c2b744 +[NSException raise:format:] + 116
4 Foundation 0x00007fff86d2b172 -[NSPathStore2 stringByAppendingPathExtension:] + 112
5 AppKit 0x00007fff9148f8c3 -[NSDocument _preserveCurrentVersionForReason:error:] + 579
6 AppKit 0x00007fff9147655b __-[NSDocument _revertToVersion:preservingFirst:error:]_block_invoke_3 + 99
7 Foundation 0x00007fff86ef28c3 __-[NSFileCoordinator coordinateReadingItemAtURL:options:error:byAccessor:]_block_invoke_1 + 113
8 Foundation 0x00007fff86ef2f34 -[NSFileCoordinator(NSPrivate) _invokeAccessor:orDont:thenRelinquishAccessClaimForID:] + 202
9 Foundation 0x00007fff86d98a28 -[NSFileCoordinator(NSPrivate) _coordinateReadingItemAtURL:options:error:byAccessor:] + 663
10 Foundation 0x00007fff86ef284c -[NSFileCoordinator coordinateReadingItemAtURL:options:error:byAccessor:] + 79
11 AppKit 0x00007fff91484b41 __-[NSDocument _revertToVersion:preservingFirst:error:]_block_invoke_1 + 347
12 AppKit 0x00007fff914901e3 -[NSDocument performSynchronousFileAccessUsingBlock:] + 42
13 AppKit 0x00007fff9148fc90 -[NSDocument _revertToVersion:preservingFirst:error:] + 125
14 AppKit 0x00007fff91476cf9 -[NSDocument _revertToDiscardRecentChangesPreservingFirst:error:] + 43
15 AppKit 0x00007fff91477094 __-[NSDocument _revertToDiscardRecentChangesThenContinue:]_block_invoke_3 + 164
16 AppKit 0x00007fff91474851 __-[NSDocument performSynchronousFileAccessUsingBlock:]_block_invoke_1 + 19
17 AppKit 0x00007fff91475bda -[NSDocument continueFileAccessUsingBlock:] + 227
18 AppKit 0x00007fff91490413 -[NSDocument _performFileAccessOnMainThread:usingBlock:] + 466
19 AppKit 0x00007fff9149023f -[NSDocument performSynchronousFileAccessUsingBlock:] + 134
20 AppKit 0x00007fff91495891 __-[NSDocument _revertToDiscardRecentChangesThenContinue:]_block_invoke_2 + 301
21 AppKit 0x00007fff914909a9 -[NSDocument _something:wasPresentedWithResult:soContinue:] + 21
22 AppKit 0x00007fff91381bee -[NSAlert didEndAlert:returnCode:contextInfo:] + 93
23 AppKit 0x00007fff9138e356 -[NSApplication endSheet:returnCode:] + 275
24 AppKit 0x00007fff91381ab4 -[NSAlert buttonPressed:] + 265
25 CoreFoundation 0x00007fff89c1b11d -[NSObject performSelector:withObject:] + 61
26 AppKit 0x00007fff911dd852 -[NSApplication sendAction:to:from:] + 139
27 AppKit 0x00007fff911dd784 -[NSControl sendAction:to:] + 88
28 AppKit 0x00007fff911dd6af -[NSCell _sendActionFrom:] + 137
29 AppKit 0x00007fff911dcb7a -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2014
30 AppKit 0x00007fff9125c57c -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 489
31 AppKit 0x00007fff911db786 -[NSControl mouseDown:] + 786
32 AppKit 0x00007fff911a666e -[NSWindow sendEvent:] + 6280
33 AppKit 0x00007fff9113ef19 -[NSApplication sendEvent:] + 5665
34 AppKit 0x00007fff910d542b -[NSApplication run] + 548
35 AppKit 0x00007fff9135352a NSApplicationMain + 867
36 myapp 0x00000001000018d2 main + 34
37 myapp 0x00000001000018a4 start + 52
)
NSDocument Subclass
#implementation MyTextDocument
#synthesize textStorage;
#synthesize textView;
+ (BOOL)autosavesInPlace
{
return YES;
}
- (id)init
{
self = [super init];
if (self) {
self.textStorage = nil;
self.textView = nil;
textContentToLoad = [#"" retain];
}
return self;
}
- (NSString *)windowNibName
{
return #"MyTextDocument";
}
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
self.textStorage = self.textView.textStorage;
[self loadTextContentIntoStorage];
}
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
return [self.textStorage.string dataUsingEncoding:NSUTF8StringEncoding];
}
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
textContentToLoad = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (!textContentToLoad) {
*outError = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:nil];
return NO;
}
[self loadTextContentIntoStorage];
return YES;
}
- (void)loadTextContentIntoStorage
{
if (!self.textStorage || !textContentToLoad)
return;
[self.textStorage beginEditing];
[self.textStorage replaceCharactersInRange:NSMakeRange(0, self.textStorage.length) withString:textContentToLoad];
[textContentToLoad release], textContentToLoad = nil;
}
#end

Is your plist set up correctly when it comes to types?
It appears that NSDocument passes the result of [self fileNameExtensionForType:[self autosavingFileType] saveOperation:NSAutosaveElsewhereOperation] to stringByAppendingPathExtension: (the method that's throwing the exception here). If your app returns nil for this expression, then this exception may result.
You should probably file a bug at Apple for this, but in the meantime, make sure your app returns something non-nil.

Paste this into you document class (e.g. Document.m):
-(NSString*)fileNameExtensionForType:(NSString *)typeName saveOperation: (NSSaveOperationType)saveOperation
{
return #"yourAutosaveExtension";
}
Before, like kperryua said, this method was not implemented and returned nil.

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.

Getting error after execute NSMutableArray

Here is the code. I tried to create a object which includes the name, size and image(get from the resource) and then I add that object into NSMutableArray in order to show those object in NSTableView. However, after I run the code, I did get the correct counts of object in NSMutableArray and correct information in each object(name,size,image), but it still gives me error. Could you guys help me. I am a new Mac developer. Thanks !!
Here is the code:
#implementation AppDelegate{
NSMutableArray* _tableContents;
}
-(void)awakeFromNib{
NSString* imagePath = #"USB.png";
NSString* mountPath = #"/Volumes";
_tableContents = [[NSMutableArray alloc]init];
for(mountPath in [[NSWorkspace sharedWorkspace]mountedLocalVolumePaths])
{
if(0==[mountPath rangeOfString:#"/Volumes/"].location)
{
NSString* USBpath = [[[NSWorkspace sharedWorkspace]mountedLocalVolumePaths]objectAtIndex:count];
//get the name of USB drive
NSString* nameOfUSB = [USBpath substringFromIndex:9];
//get the size of USB drive
NSNumber *volumeSize;
NSURL *mountPathPicked = [NSURL fileURLWithPath:mountPath];
if([mountPathPicked getResourceValue:&volumeSize forKey:NSURLVolumeTotalCapacityKey error:nil])
{
NSDictionary *obj = #{#"name":nameOfUSB,
#"image":[NSImage imageNamed:imagePath],
#"size":volumeSize
};
//after I call the following line, it will give me error !!
[_tableContents addObject:obj];
}
}
count ++;
}
}
//I also use the following two methods in order to show the name, and image in NSTableView
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{
return [_tableCountents count];
}
-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
NSDictionary *flag = _tableContents[row];
NSString *identifier = [tableColumn identifier];//call different col we need identifier
if([identifier isEqualToString:#"MainCell"])
{
NSTableCellView *cellView = [tableView makeViewWithIdentifier:#"MainCell" owner:self];//give back specific cell named mainCell
[cellView.textField setStringValue:flag[#"name"]];
[cellView.imageView setImage:flag[#"image"]];
return cellView;
}
return nil;
}
There is no connection problems in GUI. And here is the error message:
2013-04-25 01:16:41.321 NAMEOFPROJECT[8243:303] An uncaught exception was raised
2013-04-25 01:16:41.322 NAMEOFPROJECT[8243:303] *** -[__NSArrayI objectAtIndex:]: index 7 beyond bounds [0 .. 3]
2013-04-25 01:16:41.329 NAMEOFPROJECT[8243:303] (
0 CoreFoundation 0x00007fff9147cb06 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff900c03f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff9142fb53 -[__NSArrayI objectAtIndex:] + 163
3 CDTOANYDRIVE 0x00000001000011d6 -[AppDelegate DetectingUSBDrives] + 710
4 CDTOANYDRIVE 0x0000000100000efb -[AppDelegate awakeFromNib] + 43
5 AppKit 0x00007fff899631a8 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1234
6 AppKit 0x00007fff89b79976 -[NSNib _instantiateNibWithExternalNameTable:] + 610
7 AppKit 0x00007fff89b7a41a -[NSNib instantiateNibWithExternalNameTable:] + 17
8 AppKit 0x00007fff89b262b4 -[NSTableRowData _unarchiveViewWithIdentifier:owner:] + 520
9 CDTOANYDRIVE 0x000000010000174b -[AppDelegate tableView:viewForTableColumn:row:] + 219
10 AppKit 0x00007fff89b279a2 -[NSTableRowData _addViewToRowView:atColumn:row:] + 324
11 AppKit 0x00007fff89b2766f -[NSTableRowData _addViewsToRowView:atRow:] + 151
12 AppKit 0x00007fff89b25c05 -[NSTableRowData _addRowViewForVisibleRow:withPriorView:] + 415
13 AppKit 0x00007fff89b2598a -[NSTableRowData _addRowViewForVisibleRow:withPriorRowIndex:inDictionary:withRowAnimation:] + 272
14 AppKit 0x00007fff89b24c59 -[NSTableRowData _unsafeUpdateVisibleRowEntries] + 740
15 AppKit 0x00007fff89b247f1 -[NSTableRowData updateVisibleRowViews] + 119
16 AppKit 0x00007fff89afc5d7 -[NSTableView layout] + 165
17 AppKit 0x00007fff89aafe95 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 112
18 CoreFoundation 0x00007fff914754a6 __NSArrayEnumerate + 582
19 AppKit 0x00007fff89aafff6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
20 CoreFoundation 0x00007fff914754a6 __NSArrayEnumerate + 582
21 AppKit 0x00007fff89aafff6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
22 CoreFoundation 0x00007fff914754a6 __NSArrayEnumerate + 582
23 AppKit 0x00007fff89aafff6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
24 CoreFoundation 0x00007fff914754a6 __NSArrayEnumerate + 582
25 AppKit 0x00007fff89aafff6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
26 AppKit 0x00007fff89aafd2e -[NSView layoutSubtreeIfNeeded] + 615
27 AppKit 0x00007fff89aab4dc -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 201
28 AppKit 0x00007fff899d96a8 -[NSView _layoutAtWindowLevelIfNeeded] + 99
29 AppKit 0x00007fff899d8fe6 -[NSView _sendViewWillDrawInRect:clipRootView:] + 87
30 AppKit 0x00007fff899a59b1 -[NSView displayIfNeeded] + 1044
31 AppKit 0x00007fff89a62a48 -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 1377
32 AppKit 0x00007fff89a62068 -[NSWindow _doOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 940
33 AppKit 0x00007fff89a61c4f -[NSWindow orderWindow:relativeTo:] + 159
34 AppKit 0x00007fff89963266 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1424
35 AppKit 0x00007fff8994214d loadNib + 317
36 AppKit 0x00007fff89941679 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 219
37 AppKit 0x00007fff899414ae -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 200
38 AppKit 0x00007fff8994128e +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 360
39 AppKit 0x00007fff8993da2f NSApplicationMain + 398
40 CDTOANYDRIVE 0x0000000100000e82 main + 34
41 libdyld.dylib 0x00007fff9385a7e1 start + 0
42 ??? 0x0000000000000003 0x0 + 3
)
And the above error shows twice !!
I have tried your code in a mini-app and It works fine. There are few things that I might highlight:
Your exception occurs in the method DetectingUSBDrives, for which we don't have any code. I'm assuming that you have pasted the code in the awakeFromNib method.
You are using count as an index. Is this varibale initialized at zero?
The fact that the error appears twice suggests that your cell views hold a reference to your app delegate, which means that awakeFromNib is called once for each view creation. This can create many problem since you are initializing _tableOfContents there. You might want to move all that code to the init method instead.

Suggestions in popover for NSTokenField

I'm trying to subclass NSTokenField to show a popover with token suggestions.
I set my subclass as the super delegate, I intercept the – tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: delegate method and return nil to prevent the menu from showing. It works fine except by returning nil the token field doesn't complete the string entered by the user.
Currently I'm using the following lines in – tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: to add the suggested string:
NSText *editingText = [[self window] fieldEditor:NO forObject:self];
NSString *suggestionString = [filteredStrings objectAtIndex:0];
NSString *missingPart = [(NSString *)suggestionString substringFromIndex:[substring length]];
NSUInteger insertionPoint = [editingText selectedRange].location;
NSMutableString *currentStringPlusSuggestionString = [[editingText string] mutableCopy];
[currentStringPlusSuggestionString insertString:missingPart atIndex:insertionPoint];
[editingText setString:[stringWithSuggestionString copy]];
Unfortunately it generates an error when I try to insert text between 2 tokens. Here is the error but I don't really understand why the string is out of bounds.
[NSBigMutableString _getBlockStart:end:contentsEnd:forRange:stopAtLineSeparators:]: Range or index out of bounds'
0 CoreFoundation 0x00007fff88835716 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8adae470 objc_exception_throw + 43
2 CoreFoundation 0x00007fff888354ec +[NSException raise:format:] + 204
3 Foundation 0x00007fff8efd6627 -[NSString _getBlockStart:end:contentsEnd:forRange:stopAtLineSeparators:] + 157
4 AppKit 0x00007fff8bd37c6f _NSFastFillAllLayoutHolesForGlyphRange + 285
5 AppKit 0x00007fff8bd008fa -[NSLayoutManager textContainerForGlyphAtIndex:effectiveRange:] + 238
6 AppKit 0x00007fff8bb4a18f -[NSTextView(NSSharing) didChangeText] + 194
7 AppKit 0x00007fff8bbe00ee -[NSTokenFieldCell textView:willChangeSelectionFromCharacterRange:toCharacterRange:] + 776
8 AppKit 0x00007fff8bd32795 -[NSControl textView:willChangeSelectionFromCharacterRange:toCharacterRange:] + 112
9 AppKit 0x00007fff8bd30724 -[NSTextView(NSSharing) setSelectedRanges:affinity:stillSelecting:] + 1076
10 AppKit 0x00007fff8bcf8438 -[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] + 406
11 AppKit 0x00007fff8bcf828a -[NSTextStorage _notifyEdited:range:changeInLength:invalidatedRange:] + 154
12 AppKit 0x00007fff8bda0f75 -[NSTextStorage processEditing] + 202
13 AppKit 0x00007fff8bc02c54 -[NSTextStorage endEditing] + 79
14 PopoverTokenField 0x0000000100002f55 -[JSTokenField tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem:] + 1013
Alternatively, does anyone know another way to let the token field complete the string without having the menu?

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

xcode 'NSInvalidArgumentException', reason: '-[cure superview]: unrecognized selector sent to instance 0x4e3b7b0'

i am not sure why i am getting this error
i created a regular tab bar application
made 5 tabs (compiles and runs)
then put a tableview in one of the tabs , put the code below and i get this error
cure.h
#import <UIKit/UIKit.h>
#interface cure : UIViewController
<UITableViewDataSource, UITableViewDelegate>
{
NSArray *exercises;
}
#end
cure.m
#import "cure.h"
#implementation cure
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
// create a cell
if ( cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"cell"];
}
// set the main text
cell.textLabel.text = [exercises objectAtIndex:indexPath.row];
// return the cell.
return cell;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
exercises = [[NSArray alloc]
initWithObjects:#"An Interesting Title",
#"A Not That Interesting Title",
#"And Still Another Title", nil];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
in mainwindows.xib
i have the right tab class name "cure"
error
2011-04-29 22:22:06.446 week 3 week clear [4950:40b] -[cure superview]: unrecognized selector sent to instance 0x4e3b7b0
2011-04-29 22:22:06.451 peek 3 week clear [4950:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[cure superview]: unrecognized selector sent to instance 0x4e3b7b0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc15a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f15313 objc_exception_throw + 44
2 CoreFoundation 0x00dc30bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d32966 ___forwarding___ + 966
4 CoreFoundation 0x00d32522 _CF_forwarding_prep_0 + 50
5 UIKit 0x002e2365 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 77
6 UIKit 0x002e0aa3 -[UIView(Hierarchy) addSubview:] + 57
7 UIKit 0x002e87c1 -[UIView initWithCoder:] + 840
8 Foundation 0x00017c24 _decodeObjectBinary + 3296
9 Foundation 0x00016d91 _decodeObject + 224
10 UIKit 0x004ac979 -[UIRuntimeConnection initWithCoder:] + 212
11 Foundation 0x00017c24 _decodeObjectBinary + 3296
12 Foundation 0x000189f5 -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 1354
13 Foundation 0x00019024 -[NSArray(NSArray) initWithCoder:] + 596
14 Foundation 0x00017c24 _decodeObjectBinary + 3296
15 Foundation 0x00016d91 _decodeObject + 224
16 UIKit 0x004abc36 -[UINib instantiateWithOwner:options:] + 804
17 UIKit 0x004adab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
18 UIKit 0x00363628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
19 UIKit 0x00361134 -[UIViewController loadView] + 120
20 UIKit 0x0036100e -[UIViewController view] + 56
21 UIKit 0x00373f54 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 120
22 UIKit 0x00372aaa -[UITabBarController transitionFromViewController:toViewController:] + 64
23 UIKit 0x003748a2 -[UITabBarController _setSelectedViewController:] + 263
24 UIKit 0x00374711 -[UITabBarController _tabBarItemClicked:] + 352
25 UIKit 0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119
26 UIKit 0x004b3ce6 -[UITabBar _sendAction:withEvent:] + 422
27 UIKit 0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119
28 UIKit 0x00341799 -[UIControl sendAction:to:forEvent:] + 67
29 UIKit 0x00343c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
30 UIKit 0x00341750 -[UIControl sendActionsForControlEvents:] + 49
31 UIKit 0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119
32 UIKit 0x00341799 -[UIControl sendAction:to:forEvent:] + 67
33 UIKit 0x00343c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
34 UIKit 0x003427d8 -[UIControl touchesEnded:withEvent:] + 458
35 UIKit 0x002d5ded -[UIWindow _sendTouchesForEvent:] + 567
36 UIKit 0x002b6c37 -[UIApplication sendEvent:] + 447
37 UIKit 0x002bbf2e _UIApplicationHandleEvent + 7576
38 GraphicsServices 0x01719992 PurpleEventCallback + 1550
39 CoreFoundation 0x00da2944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
40 CoreFoundation 0x00d02cf7 __CFRunLoopDoSource1 + 215
41 CoreFoundation 0x00cfff83 __CFRunLoopRun + 979
42 CoreFoundation 0x00cff840 CFRunLoopRunSpecific + 208
43 CoreFoundation 0x00cff761 CFRunLoopRunInMode + 97
44 GraphicsServices 0x017181c4 GSEventRunModal + 217
45 GraphicsServices 0x01718289 GSEventRun + 115
46 UIKit 0x002bfc93 UIApplicationMain + 1160
47 peek 3 week clear 0x00002658 main + 102
48 peek 3 week clear 0x000025e9 start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
what am i doing wrong?
thank you
You have probably assigned the "cure" class to a UIView in the "Identity" tab in Interface Builder. "cure" is a view controller, so it doesn't implement any UIView methods (such as -superview), and thus throws an exception when trying to load the nib.
Btw, you have a whole bunch of leaks in your code, please read something about memory management in Objective-C (perhaps also about Cocoa naming conventions).