4

I'm learning some Objective-C/Cocoa and started to read up on handling open document events. Seems like the standard way is just via implementing application:openFile or application:openFiles in your NSApplicationDelegate.

So here's my little handler:

- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename {
    NSLog(@"Got open file! filename: %@", filename);
    return NO;
}

My question is: what does the boolean return value affect? This is not a document-based app, if that matters. I can see no discernible difference between returning YES or NO. Apple's docs aren't any help--obviously you return YES or NO to signal whether you successfully handled the open file event or not, but what are the actual consequences of these two outcomes?

I'm also not familiar enough with the framework to glean any knowledge from stepping through the call stack with the debugger.

To test my app I'm running it from Xcode (not handling cold start yet) then running it $ open -a MyApp somefile.txt commands in terminal as well as doing a File > Open With in Finder and choosing my app.

Related question, but about a different problem (unanswered): Very slow to open a file with application:openFile: after returning

Community
  • 1
  • 1
michael.bartnett
  • 787
  • 7
  • 20
  • 3
    Have you tried opening a file and returning no? I would assume that the app would reject the file and perhaps you would be switched back to the other app. The reason to reject a file would probably be if it was corrupted, too big, or something else. You're able to restrict the file type in Target > Info > Document Types, so you shouldn't reject a file because it wasn't a recognized type. – Jack Humphries Sep 03 '12 at 19:37
  • This is what I would've expected as well. But unfortunately it does not. – Julian F. Weinert Feb 07 '16 at 03:08

0 Answers0