29 questions
1
vote
2
answers
78
views
SwiftUI @ObservedObject not updating
My issue is that when I edit a template, the UI in BeginWorkoutView does not update correctly. I believe I am somehow misusing @ObservableObject/@Published/@Mainactor, but cannot for the life of me ...
2
votes
1
answer
123
views
How to Migrate a UIControl Publisher to Swift 6 Without Concurrency Warnings
I created a Publisher for UIControl based on the following code:
Original Code gist
Source: Medium article
However, when I tried migrating to Swift 6 by enabling strict concurrency checking, I ...
1
vote
1
answer
141
views
Custom snap gesture in visionOS
I’ve been developing a snap gesture for my app. While it works, it’s inconsistent and activates mistakenly.
Per Wikipedia, a snap occurs when tension is created with the index, middle, or ring finger ...
0
votes
0
answers
222
views
Updating to XCode 16.2 produces a lot of concurrency warnings
My pattern for fetching stuff from my API is like this in a ObservableObject class:
@Published var featureToggles: [FeatureToggle] = []
func fetchFeatureToggles() async -> Void {
let ...
0
votes
1
answer
267
views
How to share global constant properties?
I'm currently migrating my codebase to Swift 6 and I have global properties like these that are used in multiple areas:
extension LocalizedStringKey {
static let cancel = LocalizedStringKey("...
2
votes
1
answer
59
views
Using newBackgroundContext in @MainActor class
I have a class that fetches data from Firebase and caches it in Core Data.
import CoreData
import Firebase
@MainActor
class AccountStore: ObservableObject {
private var context = CoreDataManager....
6
votes
2
answers
3k
views
MainActor in Task
Hi I have been trying to wrap my head around the usage @MainActor in a Task, as part of Swift Concurrency.
If I have a code snippet like the one below:
Task { @MainActor in
do {
let ...
1
vote
2
answers
1k
views
Correct usage of @Observable and @MainActor
Say I have a simple view:
struct MyView: View {
var viewModel = MyViewModel() //see error message below
var body: some View {
List(viewModel.cats, id:\.id) { cat in
...
0
votes
1
answer
79
views
Don't understand SCNSceneRenderer delegate data race warning
My app needs a reference to the SCNSceneRenderer for hit testing. I thus use SCNSceneRenderer delegate to get and store the reference as property in my ViewModel:
@MainActor
@Observable
final class ...
0
votes
1
answer
568
views
Cannot initialize MainActor isolated class from another
I have this little piece of code that won't compile due to Call to main actor-isolated initializer 'init(username:)' in a synchronous nonisolated context.
I don't understand, since as you'll see both ...
1
vote
1
answer
1k
views
In swift, do we need "@MainActor in" inside the closure of an other object written inside ViewController?
I have seen code like this
func connectVCAndVM() {
// Setting up a closure to be called when data in the viewModel changes
viewModel.dataChanged = { [weak self] in
Task { @MainActor ...
5
votes
0
answers
2k
views
@Observable vs @MainActor return Call to main actor-isolated initializer 'init()' in a synchronous nonisolated context
I'm working with DataScannerViewController to give the user the ability to recognize text using the camera.
I created a template to manage camera permissions.
I uses @Observable macro and I need to ...
1
vote
1
answer
437
views
Concurrency problem when only parts of a class are annotated with @MainActor
I have set Strict Concurrency Checking to Complete, and the following code compiles without warnings in Xcode 15.0.1 and Xcode 15.1 beta 3.
When running it, it shows a concurrency problem. The inc() ...
0
votes
1
answer
536
views
Swift compiler Warning Converting function value of type @MainActor loses global actor MainActor
I am using Swift UI. I created simple search function to filter the data. OnChnage function I am calling the State property wrapper with view model search function. I done some research that , the ...
1
vote
1
answer
241
views
Why is the following code not running on the main thread?
When I mark a protocol with async functions with @MainActor and it's conformance does not specify it's functions are async, it is not executing on main thread. I don't know if this is a bug or not.
...