Open file in Finder does not work on App launch

Hi! I have a strange issue for my SwiftUI based App on macOS.

Opening and saving a file works well when the app is already open. But when I double click a file in Finder to launch the App the file is not opened. When I double click the file again it gets loaded.

I assume that I missed something simple but I can't get a clue from documentation and internet searching.

Any clue how to proceed to open a file on application launch?

Answered by GreatOm in 750691022

To answer my own question:

There is currently no "SwiftUI like“ way to handle this.

So use just the old way via AppDelegate:

final class AppDelegate: NSObject, NSApplicationDelegate {

    func application(_ application: NSApplication, open urls: [URL]) {
        // Read the provided URLs
        }
    }
Accepted Answer

To answer my own question:

There is currently no "SwiftUI like“ way to handle this.

So use just the old way via AppDelegate:

final class AppDelegate: NSObject, NSApplicationDelegate {

    func application(_ application: NSApplication, open urls: [URL]) {
        // Read the provided URLs
        }
    }
Open file in Finder does not work on App launch
 
 
Q