GithubHelp home page GithubHelp logo

"Reference to class property 'enabled' is not concurrency-safe because it involves shared mutable state" with Strict Concurrency Checking = Complete about showtime HOT 6 OPEN

kanecheshire avatar kanecheshire commented on September 26, 2024 1
"Reference to class property 'enabled' is not concurrency-safe because it involves shared mutable state" with Strict Concurrency Checking = Complete

from showtime.

Comments (6)

KaneCheshire avatar KaneCheshire commented on September 26, 2024 3

Hey! Thank you for raising this and for putting together a sample project. I'll take a look and try and fix it :)

from showtime.

KaneCheshire avatar KaneCheshire commented on September 26, 2024

Hey :) sorry for the delay. So I think the solution to this is to just annotate the ShowTime type with @MainActor to enforce that it and any of its properties etc can only be used in a @MainActor isolated environment.

This would mean that any place it's being used needs to be annotated with @MainActor as well; luckily UIApplicationDelegate already is annotated with @MainActor but if you're using any ShowTime property in a SwiftUI view you'll probably need to annotate the view with @MainActor explicitly, which is a bit annoying but is technically correct for async code.

from showtime.

cderito avatar cderito commented on September 26, 2024

Hi @KaneCheshire, thanks for looking into it! By annotating the ShowTime type with @MainActor what do you mean exactly? Because in my code I'm directly using its static variables so I can't do something like

@MainActor let showTime = ShowTime()

or similar, and both the App and UIApplicationDelegate in which I use it are already annotated with @MainActor.

Do you mean I should create an extension for ShowTime and annotate it?

Thank you!

from showtime.

KaneCheshire avatar KaneCheshire commented on September 26, 2024

@cderito oh sorry no I explained that badly. What I mean is, the ShowTime type itself needs to be updated in this repo to be annotated with @MainActor for strict concurrency. So it's nothing you're doing wrong at all, the compiler is just expecting us to isolate the getters and setters of the properties for strict concurrency.

My main concern with doing this is that even people who don't have strict concurrency mode enabled yet will be forced to add @MainActor to their SwiftUI views or anywhere they're accessing ShowTime properties in places not yet isolated to @MainActor 🤔

from showtime.

cderito avatar cderito commented on September 26, 2024

Oh I see! I had a 1:1 with an Apple engineer about Swift Concurrency some time after opening this issue and I got to know that there's a @preconcurrency attribute that can be used inline with import declarations to silence warnings but I couldn't get it to silence this particular warning, it seems it's dedicated to Sendable related warnings.

Anyway this will probably become an error only once Swift 6 is out so I think the fix doesn't need to be immediate, it could just be planned in a roadmap to Swift 6, or rolled out at least once this flag becomes on by default in some Xcode release, what do you think about it?

from showtime.

mkoorn avatar mkoorn commented on September 26, 2024

@KaneCheshire Any plans on updating the lib with a fix for this?
Thanks for your effort on this lib.

from showtime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.