|
I'm trying to figure out the correct structure for a macOS document app using SwiftUI and Swift 5.5 concurrency features. I want to demonstrate updating a document's data asynchronously, in a thread safe manner, with the ability to read / write the data to a file, also thread-safe and in the background. Yet I am struggling to:
I'm seeking ideas, corrections and advice on how to improve on this. I've posted the full code over at GitHub, as I will only highlight some particular elements here. This is a minimum viable app, just for proof-of-concept purposes. The app The app displays a list of Current approach / design I've chosen the
The app assumes that the func to add an item takes a long time, and hence runs it from with a The code compiles and runs allowing new items to be added to the list but... Issues Firstly, I can't annotate Secondly, I therefore have a clunky way for
Finally, I can't get the
|
|
I've worked out a solution - it's taken my way too long: I feel daft looking back on my first clumsy attempt. Two of my key mistakes were to put the my Here's the original attempt:
My new approach doesn't create an actor, but puts a property Here's the new view model class:
This has succeeded in ensuring the code is free of race-conditions, whilst keeping processing and update syncronisation of the record's array off the main thread, and removing all the other issues I encountered such as trying to conform the actor to I've left the full updated project at GitHub |
SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.