Have you already tried to create a macOS document based app with SwiftUI and the new
App protocol? Well, there are some problems to solve esp. if you want to use menus focused on the currently open document.
In the old app cycle with
AppDelegate / SceneDelegate you still had to use the storyboard to define the menu items and link them to your methods in your document class derived from
NSDocument. Enabling and disabling of the menu item according to the open documents was automatically managed by the frameworks.
That’s not the case in the new
App protocol of SwiftUI anymore. Instead, you can define your menus and menu items quite nicely in your
App struct conforming to the new
App protocol but there is no automatic link to the current document in focus.
Currently, I am developing a quite complex Mac application using Core Data together with SwiftUI. The first challenge I encountered was the SwiftUI preview. I implemented a special preview model with some test data that is assigned to the preview structs of my views as EnvironmentObject. That works fine and I enriched my application step by step.
Well, but suddenly the previews stopped to work. I always got the error message „
Updating took more than 5 seconds.“ I suspected one of the recent changes to screw up my work although the completely built applications still worked fine. I walked through my code and certainly found some problematic points but nothing could make the preview show up again.
I couldn’t resist. Now, the new Apple Silicon macs are out and I had to buy a new Mac mini to test my applications on the new architecture (and the new macOS 11.0). Recently I released my refurbished project, the call center simulator CCsim (https://apps.apple.com/de/app/ccsim/id1519438028?mt=12). It is heavily relying on multithreading and I was eager to see what it is doing on M1-equipped macs. Weiterlesen
Recently I have migrated an old project of mine from Objective-C to Swift. It was not that difficult and it worked out fine, and I was eager to see how the performance of the migrated system would turn out. How big was my disappointment when I saw that the Swift version of my system was at least a factor of 10 slower than the Objective-C version with unchanged functionality. That can’t be true, I thought and debugged at little bit.
Some time ago I’ve ported the old and ancient strategy game „Empire“ from macOS to iOS. On macOS I decided to make the game document based. Since the game may last many hours (or even more), it is necessary to store the state of the game in some kind of document to continue it in a later session. On start-up of the game it tries to re-open the last used document. That’s quite easy with the
recentDocumentURLs array of the
But for iOS such a facility is missing. There is no such thing as a „UIDocumentController“ and the
UIDocumentBrowserViewController tells you nothing about recently opened or created documents. I wanted to make the iOS version of Empire document based as well to enable anytime switches between the iOS and macOS version of the game. That’s especially interesting, if the game document is stored on some external server (like iCloud).