textView:shouldChangeTextInRanges:replacementStrings: method crashes when NSTextStorage is edited - macos

I'm new to Cocoa programming under OSX Lion, so this is a question I cannot find answer to.
I need to modify an attributed string which is entered by the user through the NSTextView.
Editing may include replacement of some portion(s) of the string inside the NSTextStorage and addition of NSTextAttachment objects.
I implemented the protocol and provided it for NSTextView instance as delegate.
I also implemented the method textView:shouldChangeTextInRanges:replacementStrings: in the next manner:
- (BOOL)textView:(NSTextView *)textView shouldChangeTextInRanges:(NSArray *)affectedRanges replacementStrings:(NSArray *)replacementStrings{
NSTextStorage* ts=[textView textStorage];
[ts beginEditing];
NSMutableString* buf=[ts mutableString];
//make some completions
NSRange rng;
rng.location=0;
rng.length=[buf length];
[buf replaceOccurrencesOfString:#"(." withString:#"(0." options:0 range:rng];
rng.location=0;
rng.length=[buf length];
[buf replaceOccurrencesOfString:#"-+" withString:#"-" options:0 range:rng];
rng.location=0;
rng.length=[buf length];
[buf replaceOccurrencesOfString:#"+-" withString:#"-" options:0 range:rng];
[ts endEditing];
return YES;
}
Thus I try the next scenario: when the application is up, the user types inside the NSTextView some text. If he types "(." everything is going well. But when he types "-+ " (minus, plus, whitespace) - the method crashes producing this dump:
[NSConcreteTextStorage attributesAtIndex:effectiveRange:]: Range or index out of bounds
(
0 CoreFoundation 0x00007fff95963286 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8c32bd5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff959630ba +[NSException raise:format:arguments:] + 106
3 CoreFoundation 0x00007fff95963044 +[NSException raise:format:] + 116
4 AppKit 0x00007fff90acb5bd -[NSConcreteTextStorage attributesAtIndex:effectiveRange:] + 121
5 AppKit 0x00007fff90f4cde6 -[NSTextView insertText:replacementRange:] + 840
6 AppKit 0x00007fff910fc891 -[NSTextInputContext handleTSMEvent:] + 2289
7 AppKit 0x00007fff910fe4fe _NSTSMEventHandler + 165
8 HIToolbox 0x00007fff89745308 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1263
9 HIToolbox 0x00007fff89744914 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 446
10 HIToolbox 0x00007fff8975b6c7 SendEventToEventTarget + 76
11 HIToolbox 0x00007fff89930a4d SendTSMEvent + 35
12 HIToolbox 0x00007fff89930dd4 SendUnicodeTextAEToUnicodeDoc + 452
13 HIToolbox 0x00007fff8993095e TSMKeyEvent + 629
14 HIToolbox 0x00007fff8976f81a TSMProcessRawKeyEvent + 2350
15 AppKit 0x00007fff910fbade -[NSTextInputContext handleEvent:] + 639
16 AppKit 0x00007fff90fc7eaf -[NSView interpretKeyEvents:] + 248
17 AppKit 0x00007fff90f40c65 -[NSTextView keyDown:] + 691
18 AppKit 0x00007fff90a20544 -[NSWindow sendEvent:] + 7430
19 AppKit 0x00007fff909b868f -[NSApplication sendEvent:] + 5593
20 AppKit 0x00007fff9094e682 -[NSApplication run] + 555
21 AppKit 0x00007fff90bcd80c NSApplicationMain + 867
22 myapp 0x0000000100001302 main + 34
23 myapp 0x00000001000012d4 start + 52
It seems that shortened string causes some out-of-bounds spill.
What am I doing wrong and how can I fix this issue? Please help.

The -length method returns the quantity of characters in a NSString. The problem is that the first character is in the index 0. Try using [buf length] - 1. This should work.

Related

Coredata bound NSNumber column on tableview crashes when attempting to edit

I have created (without coding) a coredata entity and a cocoa window that displays the rows in an editable tableview that is bound to an array controller bound to the entity. There is one NSNumber column in the table, which without a custom value transformer crashes on editing because the column form the tableview tries to save as a string.
So I created a custom value transformer which i linked to that column but i now get different errors. Here is my code:
#import "StringToNumberTransformer.h"
#implementation StringToNumberTransformer
+ (Class)transformedValueClass { return [NSNumber class]; }
+ (BOOL)allowsReverseTransformation { return NO; }
- (id)transformedValue:(id)value {
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * _menuId = [f numberFromString:[value stringValue]];
return _menuId;
}
#end
Here is the error i get as soon as i click on the column:
[EntityName stringValue]: unrecognized selector sent to instance 0x100137de0
0 CoreFoundation 0x00007fff876dbb06 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff836593f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8777240a -[NSObject(NSObject) doesNotRecognizeSelector:] + 186
3 CoreFoundation 0x00007fff876ca02e ___forwarding___ + 414
4 CoreFoundation 0x00007fff876c9e18 _CF_forwarding_prep_0 + 232
5 ClickerData 0x0000000100001439 -[StringToNumberTransformer transformedValue:] + 153
6 AppKit 0x00007fff8a556612 -[NSBinder valueForBinding:atIndex:resolveMarkersToPlaceholders:] + 528
7 AppKit 0x00007fff8a6bb947 -[NSEditableBinder editableStateAtIndex:] + 80
8 AppKit 0x00007fff8a83bc2b -[NSTableBinder tableView:shouldEditTableColumn:row:] + 168
9 AppKit 0x00007fff8a94f2b7 -[_NSBindingAdaptor tableView:shouldEditTableColumn:row:] + 157
10 AppKit 0x00007fff8a849cd1 -[NSTableView _userCanEditTableColumn:row:] + 65
11 AppKit 0x00007fff8a849dad -[NSTableView _userCanSelectAndEditTableColumn:row:] + 97
12 AppKit 0x00007fff8a851ec8 -[NSTableView _shouldEditColumn:row:withEvent:] + 121
13 AppKit 0x00007fff8a854861 -[NSTableView mouseDown:] + 5858
14 AppKit 0x00007fff8a44250e -[NSWindow sendEvent:] + 6853
15 AppKit 0x00007fff8a43e644 -[NSApplication sendEvent:] + 5761
16 AppKit 0x00007fff8a35421a -[NSApplication run] + 636
17 AppKit 0x00007fff8a2f8bd6 NSApplicationMain + 869
18 ClickerData 0x0000000100002bf2 main + 34
19 libdyld.dylib 0x00007fff842be7e1 start + 0
20 ??? 0x0000000000000003 0x0 + 3
)
What am i doing wrong here? I just want to be able to enter a number and let it save back to the entity.
Many thanks

How to disable the auto-reopening of the last document?

How to disable the auto-reopening of the last document ?
When I execute my application, it calls the method readFromData.
But, the problem is that between my version 1 and my version 2, I changed the structure of the data that is saved by the application. In v1, the root object was an array. In v2, the root object is a dictionnary with two keys, one for a string, and one for an array.
When the application loads, it seems that it load from the data an array and then tries to get from this array an object for the keys of the dictionnary.
What shall I do !!??
PS : I tried to create a NSApplicationDelegate with
-(BOOL)applicationShouldOpenUntitledFile:(NSApplication*)app
{
return YES;
}
- (BOOL)applicationOpenUntitledFile:(NSApplication *)sender
{
return YES ;
}
but these methods are never called by my application.
EDIT :
Here is the call stack :
0 CoreFoundation 0x00007fff8bc06f56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff81f37d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8bc931be -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff8bbf3e23 ___forwarding___ + 371
4 CoreFoundation 0x00007fff8bbf3c38 _CF_forwarding_prep_0 + 232
5 dictionnaireDouchoutique 0x0000000100007f22 -[Document readFromData:ofType:error:] + 498
6 AppKit 0x00007fff89af3558 -[NSDocument readFromURL:ofType:error:] + 665
7 AppKit 0x00007fff8999198c -[NSDocument _initForURL:withContentsOfURL:ofType:error:] + 151
8 AppKit 0x00007fff89991890 -[NSDocument initForURL:withContentsOfURL:ofType:error:] + 360
9 AppKit 0x00007fff89991677 -[NSDocumentController makeDocumentForURL:withContentsOfURL:ofType:error:] + 199
10 AppKit 0x00007fff8999150f __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_5 + 150
11 AppKit 0x00007fff89991467 __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_4 + 697
12 AppKit 0x00007fff899911a9 -[NSDocumentController _openDocumentWithContentsOfURL:usingProcedure:] + 530
13 AppKit 0x00007fff89990d95 __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_3 + 242
14 libdispatch.dylib 0x00007fff86329a82 _dispatch_call_block_and_release + 18
15 libdispatch.dylib 0x00007fff8632b8f2 _dispatch_main_queue_callback_4CF + 308
16 CoreFoundation 0x00007fff8bb9be7c __CFRunLoopRun + 1724
17 CoreFoundation 0x00007fff8bb9b486 CFRunLoopRunSpecific + 230
18 HIToolbox 0x00007fff87d652bf RunCurrentEventLoopInMode + 277
19 HIToolbox 0x00007fff87d6c56d ReceiveNextEventCommon + 355
20 HIToolbox 0x00007fff87d6c3fa BlockUntilNextEventMatchingListInMode + 62
21 AppKit 0x00007fff8973d779 _DPSNextEvent + 659
22 AppKit 0x00007fff8973d07d -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135
23 AppKit 0x00007fff897399b9 -[NSApplication run] + 470
24 AppKit 0x00007fff899b5eac NSApplicationMain + 867
25 dictionnaireDouchoutique 0x00000001000075d2 main + 34
26 dictionnaireDouchoutique 0x0000000100001984 start + 52
In your NSDocument subclass, override + (BOOL)autosavesDraft and return NO, and you will be safe during your development. However, once you are in production, you should handle the different file formats you have without crashing...
Use NSPropertyListSerialization to deserialize the data, then use respondsToSelector: or isKindOfClass: checks to see what kind of root object it handed you. If it's an array, handle that; if it's a dictionary, handle that; if it's anything you don't recognize, return an error indicating that the file is garbage.
You don't list how you implemented readFromData:, but if you are using NSKeyedUnarchiver you can use containsValueForKey: to validate the objects in the data parameter.
If you want to make old versions incompatible, you can detect old version and populate the error parameter.

Out of bounds error on addObject to NSMutableDictionary

So I am building an app in cocoa and having a bit of trouble. I want to feed text file names in many different folders to a tableview using an array controller, but it keeps throwing out of bounds errors. Heres a chunk of the code giving me trouble.
[self clear:nil]; // method that clears the NSTableView
NSString *chooserSelection = chooserItems.titleOfSelectedItem; // gets the selected folder from an NSPopUpButton
if (chooserSelection == #"All") {
path = #"/Library/Application Support/File Folder/Files/";
NSArray *folders = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
NSLog(#"\nfolders = %#", folders);
for (int i = 0; i < [folders count]; i++) {
path = #"/Library/Application Support/File Folder/Files/";
NSMutableString *folderNames = [[NSMutableString stringWithString:path] init];
[folderNames insertString:folders[i] atIndex:folderNames.length];
[folderNames insertString:#"/" atIndex:folderNames.length];
NSArray *text = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:folderNames error:nil];
[myArrayController addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys:text[i], #"File Name", nil]];
//This line gives the error
}
}
If I change [folders count] to 1 it shows up in the NSTableView. However on anything past that (additional passes through the for loop) i get an out of bounds error.
2013-02-26 13:17:49.679 AppName[3489:403] *** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]
2013-02-26 13:17:49.683 AppName[3489:403] (
0 CoreFoundation 0x00007fff829b5f56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff84fe6d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8295f370 -[__NSArrayI objectAtIndex:] + 208
3 AppName 0x000000010000159a -[AppDelegate tableView:objectValueForTableColumn:row:] + 106
4 AppKit 0x00007fff840a16e7 -[NSTableView _dataSourceValueForColumn:row:] + 73
5 AppKit 0x00007fff840a1167 -[NSTableView preparedCellAtColumn:row:] + 437
6 AppKit 0x00007fff840b2171 -[NSTableView _drawContentsAtRow:column:withCellFrame:] + 42
7 AppKit 0x00007fff840b05d8 -[NSTableView drawRow:clipRect:] + 1647
8 AppKit 0x00007fff840afdb5 -[NSTableView drawRowIndexes:clipRect:] + 565
9 AppKit 0x00007fff840aded7 -[NSTableView drawRect:] + 1390
10 AppKit 0x00007fff84197382 -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inContext:topView:] + 1435
11 AppKit 0x00007fff841b564f __-[NSView(NSLayerKitGlue) drawLayer:inContext:]_block_invoke_1 + 94
12 AppKit 0x00007fff841b52fb -[NSView(NSLayerKitGlue) _drawViewBackingLayer:inContext:drawingHandler:] + 2001
13 QuartzCore 0x00007fff82c4a0dc -[CALayer drawInContext:] + 145
14 QuartzCore 0x00007fff82c49225 CABackingStoreUpdate_ + 3221
15 QuartzCore 0x00007fff82c4813a _ZN2CA5Layer8display_Ev + 1086
16 AppKit 0x00007fff841504e6 -[NSView(NSInternal) _recursiveDisplayViewsIntoLayersIfNeeded] + 163
17 AppKit 0x00007fff841505fc -[NSView(NSInternal) _recursiveDisplayViewsIntoLayersIfNeeded] + 441
18 AppKit 0x00007fff841505fc -[NSView(NSInternal) _recursiveDisplayViewsIntoLayersIfNeeded] + 441
19 AppKit 0x00007fff841505fc -[NSView(NSInternal) _recursiveDisplayViewsIntoLayersIfNeeded] + 441
20 AppKit 0x00007fff84150168 -[NSView(NSLayerKitGlue) _drawRectAsLayerTree:] + 128
21 AppKit 0x00007fff8401653e -[NSView _drawRect:clip:] + 4382
22 AppKit 0x00007fff8401406d -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 3020
23 AppKit 0x00007fff84014b5e -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5821
24 AppKit 0x00007fff84012da3 -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 270
25 AppKit 0x00007fff8400e1bb -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 4755
26 AppKit 0x00007fff84006c35 -[NSView displayIfNeeded] + 1676
27 AppKit 0x00007fff84006375 _handleWindowNeedsDisplayOrLayoutOrUpdateConstraints + 648
28 CoreFoundation 0x00007fff829758e7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
29 CoreFoundation 0x00007fff82975846 __CFRunLoopDoObservers + 374
30 CoreFoundation 0x00007fff8294aaf9 __CFRunLoopRun + 825
31 CoreFoundation 0x00007fff8294a486 CFRunLoopRunSpecific + 230
32 AppKit 0x00007fff84459b08 -[NSMenu _internalPerformActionForItemAtIndex:] + 38
33 AppKit 0x00007fff842e86f9 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 138
34 AppKit 0x00007fff841349bb NSSLMMenuEventHandler + 339
35 HIToolbox 0x00007fff89d08234 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1263
36 HIToolbox 0x00007fff89d07840 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 446
37 HIToolbox 0x00007fff89d1e6db SendEventToEventTarget + 76
38 HIToolbox 0x00007fff89d647b5 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 398
39 HIToolbox 0x00007fff89e4be2d SendMenuCommandWithContextAndModifiers + 56
40 HIToolbox 0x00007fff89e935b5 SendMenuItemSelectedEvent + 253
41 HIToolbox 0x00007fff89d5d883 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 101
42 HIToolbox 0x00007fff89e8bfed _ZL19PopUpMenuSelectCoreP8MenuData5PointdS1_tjPK4RecttjS4_S4_PK10__CFStringPP13OpaqueMenuRefPt + 1660
43 HIToolbox 0x00007fff89e8c2ac _HandlePopUpMenuSelection7 + 621
44 AppKit 0x00007fff842eb3c5 _NSSLMPopUpCarbonMenu3 + 3860
45 AppKit 0x00007fff846990fa _NSPopUpCarbonMenu3 + 39
46 AppKit 0x00007fff842e952a -[NSCarbonMenuImpl popUpMenu:atLocation:width:forView:withSelectedItem:withFont:withFlags:withOptions:] + 322
47 AppKit 0x00007fff844ca1f1 -[NSPopUpButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 564
48 AppKit 0x00007fff840cb7f6 -[NSControl mouseDown:] + 786
49 AppKit 0x00007fff84096c98 -[NSWindow sendEvent:] + 6306
50 AppKit 0x00007fff840303a5 -[NSApplication sendEvent:] + 5593
51 AppKit 0x00007fff83fc6a0e -[NSApplication run] + 555
52 AppKit 0x00007fff84242eac NSApplicationMain + 867
53 AppName 0x0000000100001152 main + 34
54 AppName 0x0000000100001124 start + 52
)
I can also more the addObject line to the line below the for loop which will display the filename of the last file. But I cannot figure out where the out of bounds error is coming from.
You are using the index i first for the count of folders in path, and then for the count of files in that respective folder. So you are depending on there being at least as many files in folder N as the number of N.
For example if you have three folders
folder0
folder1
folder2
then when you iterate over folder2 (i=2), there had better be at least 3 items in the folder as you are accessing item 3 (text[2]). When there are fewer items, you will get that out-of-bounds error.
You probably mean to do something like this:
NSMutableDictionary* dict =
[NSMutableDictionary dictionaryWithObjectsAndKeys:text, folders[i], nil];
That will get you an array of dictionaries. Each dictionary has a single key (the name of the folder,) and a single value (an array of filenames).
You could simplify your data structure further by flattening this to a single dictionary (not inside an array). Each key is a folder name, each value is the array of filenames.

Proper way to close NSDocument programmatically

I have a subclass of NSDocument that crashes whenever I use [self close] to avoid the default 'save' dialog for new documents:
2013-02-25 15:23:06.338 MyApp[692:403] An uncaught exception was raised
2013-02-25 15:23:06.338 MyApp[692:403] NSWindow: -_newFirstResponderAfterResigining is not a valid message outside of a responder's implementation of -resignFirstResponder.
2013-02-25 15:23:06.356 MyApp[692:403] (
0 CoreFoundation 0x00007fff8b2cdf56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff88c00d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8b2cdd8a +[NSException raise:format:arguments:] + 106
3 CoreFoundation 0x00007fff8b2cdd14 +[NSException raise:format:] + 116
4 AppKit 0x00007fff858e0c34 -[NSWindow _newFirstResponderAfterResigning] + 164
5 AppKit 0x00007fff85882c8a -[NSTextView(NSSharing) resignFirstResponder] + 54
6 AppKit 0x00007fff8536dd79 -[NSWindow makeFirstResponder:] + 429
7 AppKit 0x00007fff85488dfb -[NSWindow dealloc] + 802
8 AppKit 0x00007fff8528b955 -[NSWindow release] + 535
9 AppKit 0x00007fff858b541c __destroy_helper_block_4 + 26
10 libsystem_blocks.dylib 0x00007fff8702b174 _Block_release + 181
11 libdispatch.dylib 0x00007fff84ab28f2 _dispatch_main_queue_callback_4CF + 308
12 CoreFoundation 0x00007fff8b262e7c __CFRunLoopRun + 1724
13 CoreFoundation 0x00007fff8b262486 CFRunLoopRunSpecific + 230
14 HIToolbox 0x00007fff8d64e2bf RunCurrentEventLoopInMode + 277
15 HIToolbox 0x00007fff8d65556d ReceiveNextEventCommon + 355
16 HIToolbox 0x00007fff8d6553fa BlockUntilNextEventMatchingListInMode + 62
17 AppKit 0x00007fff85252779 _DPSNextEvent + 659
18 AppKit 0x00007fff8525207d -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135
19 AppKit 0x00007fff8524e9b9 -[NSApplication run] + 470
20 AppKit 0x00007fff854caeac NSApplicationMain + 867
21 MyApp 0x00000001059098d2 main + 34
22 MyApp 0x00000001059098a4 start + 52
23 ??? 0x0000000000000003 0x0 + 3
)
Has anyone seen this before or can anyone suggest a better/proper way to close an NSDocument without the save dialog being shown?
So judging by your followup comments, what you're trying to do is suppress the standard close confirmation sheet under specific circumstances. Some ways to do that:
Adopt autosaving-in-place, which moves away from the ancient paradigm of manually saving documents
Override -[NSDocument canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:] so it tells the delegate "yes, you can close", rather than presenting a sheet
Once a post is made, call [document updateChangeCount: NSChangeCleared] to inform the document that you consider it to be saved

Passing value between NSTabView

I try to do a simple program in cocoa, a NSTabVew with 2 items, in the first item I set a content to a string var, in the second tab I display this value. I create two Object class (Prima and Seconda), than I add 2 object in IB setting like Prima and Seconda
Prima.m
- (IBAction) salva:(id) sender{
nome = [field stringValue];
NSLog(#"%#",nome);
}
Seconda.m
- (IBAction) visualizza:(id) sender{
NSString *dato;
Prima *prima = [[Prima alloc] init];
dato = prima.nome;
[label setStringValue:dato];
}
when I run the program I get this error:
2011-10-03 11:42:43.511 Prova[44622:707] *** Assertion failure in -[NSTextFieldCell _objectValue:forString:errorDescription:], /SourceCache/AppKit/AppKit-1138/AppKit.subproj/NSCell.m:1564
2011-10-03 11:42:43.511 Prova[44622:707] Invalid parameter not satisfying: aString != nil
2011-10-03 11:42:43.513 Prova[44622:707] (
0 CoreFoundation 0x00007fff8d497986 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff90ed9d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8d4977ba +[NSException raise:format:arguments:] + 106
3 Foundation 0x00007fff8cce914f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 169
4 AppKit 0x00007fff88957685 -[NSCell _objectValue:forString:errorDescription:] + 160
5 AppKit 0x00007fff889575df -[NSCell _objectValue:forString:] + 19
6 AppKit 0x00007fff88957545 -[NSCell setStringValue:] + 41
7 AppKit 0x00007fff88a58039 -[NSControl setStringValue:] + 115
8 Prova 0x0000000100001365 -[Seconda visualizza:] + 133
9 CoreFoundation 0x00007fff8d48711d -[NSObject performSelector:withObject:] + 61
10 AppKit 0x00007fff88a3f852 -[NSApplication sendAction:to:from:] + 139
11 AppKit 0x00007fff88a3f784 -[NSControl sendAction:to:] + 88
12 AppKit 0x00007fff88a3f6af -[NSCell _sendActionFrom:] + 137
13 AppKit 0x00007fff88a3eb7a -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2014
14 AppKit 0x00007fff88abe57c -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 489
15 AppKit 0x00007fff88a3d786 -[NSControl mouseDown:] + 786
16 AppKit 0x00007fff88a0866e -[NSWindow sendEvent:] + 6280
17 AppKit 0x00007fff889a0f19 -[NSApplication sendEvent:] + 5665
18 AppKit 0x00007fff8893742b -[NSApplication run] + 548
19 AppKit 0x00007fff88bb552a NSApplicationMain + 867
20 Prova 0x0000000100000f92 main + 34
21 Prova 0x0000000100000f64 start + 52
22 ??? 0x0000000000000001 0x0 + 1
)
where is the error for you?
It seems that dato is nil, which (based on what you've given us) is probably because things aren't hooked up right in the XIB. Without more information I can't say more.

Resources