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
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.