Call to main actor-isolated instance method XXX in a synchronous nonisolated context

This is bug in current swift versions as compiler is not able to recognize the global actor context for a defer block, the discussion for this is going on swift forum and a PR with fix also available that should resolve this issue in future swift versions. For now, explicitly global actor context need to … Read more

How to prevent actor reentrancy resulting in duplicative requests?

UPDATE Apple’s developer web site now includes the code snippets for WWDC videos (at least for 2021 and later). You can find the “better solution” code on the video’s page by tapping the “Code” tab under the video player and scrolling down to “11:59 – Check your assumptions after an await: A better solution”. ORIGINAL … Read more

Swift, actor: Actor-isolated property ‘scanning’ can not be mutated from a non-isolated context

How can I use an actor to store/read state information correctly so the MyObj can use it to read and set state? You cannot mutate an actor’s instance variables from outside the actor. That is the whole point of actors! Instead, give the actor a method that sets its own instance variable. You will then … Read more

Swift await/async – how to wait synchronously for an async task to complete?

You should not wait synchronously for an async task. One may come up with a solution similar to this: func updateDatabase(_ asyncUpdateDatabase: @Sendable @escaping () async -> Void) { let semaphore = DispatchSemaphore(value: 0) Task { await asyncUpdateDatabase() semaphore.signal() } semaphore.wait() } Although it works in some simple conditions, according to WWDC 2021 Swift Concurrency: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)