mastodon.world is one of the many independent Mastodon servers you can use to participate in the fediverse.
Generic Mastodon server for anyone to use.

Server stats:

8.4K
active users

Swift Dev Journal

SwiftUI Mac windows question.

Suppose I’m making a git client. I want one window per repo, something like document windows, without using the document architecture. What would be the best way to do this?

A git client wouldn’t use most of the document architecture. WindowGroup seems like it’s for opening additional windows and not for document-like windows.

@swiftdevjournal What exactly do you mean by "document-like windows" here that WindowGroup doesn't provide?

@bwebster As a test I tried selecting a folder from an Open panel and opening a window with the folder name in the title. When I selected a folder, the original window appeared over the newly created window. When I created additional windows, a second copy of the original window opened, and sometimes the other folders I created disappeared.

@swiftdevjournal Ah, so basically uniquing the windows on a per-URL basis. Yeah, it does look like WindowGroup doesn't have a way to do that. If your windows are always associated with a file URL (or new), then using DocumentGroup should work. I would think if you set up your document type in Info.plist to have a Viewer role, it would disable all the various save menu items etc. I've never experimented with it though.

@bwebster Thanks for the confirmation.

I tried DocumentGroup, but it doesn’t work well with folder URLs. The Open panel doesn’t close when I select a folder and click the Open button. The panel navigates to the folder’s contents.

@swiftdevjournal Yeah, to be honest if you're doing anything at all outside the box, you can hit the wall with the SwiftUI app lifecycle pretty hard on macOS. I'd recommend switching to the AppKit lifecycle sooner rather than later, it'll only get worse as the app grows.

@swiftdevjournal Not near a computer right now but I think this is where you need Window with an id or attached parameter that contains the URL.

@troz Passing a URL as the value to openWindow worked. Thanks.

@swiftdevjournal windowGroup windows can be opened by their ID with an accompanying value. Use that value to dictate the underlying data source of that particular window.

@puppethead That’s an interesting approach. Thanks for sharing the article. I’ll see how it works.