hmlongco / Factory

A new approach to Container-Based Dependency Injection for Swift and SwiftUI.
MIT License
1.83k stars 115 forks source link

complete Swift Concurrency Checking: "Reference to class property 'shared' is not concurrency-safe because it involves shared mutable state" #165

Closed LucasVanDongen closed 6 months ago

LucasVanDongen commented 10 months ago

After setting "Swift Concurrency Checking" to complete, I started getting warnings accessing the shared Container in my tests:

Reference to class property 'shared' is not concurrency-safe because it involves shared mutable state

Relevant code:

@MainActor
class ActionLoaderTests: XCTestCase {
    // ...
    private let container = Container.shared // Here's the warning
    // ...

    override func setUpWithError() throws {
        // Resetting the container
        container.manager.reset()

        // Setting up and registering the mocks to reasonable default values / responses so happy path will succeed
        logHandler = LogHandlingMock()
        container.logHandler.register { self.logHandler }
    }
}

Is there a smart way around this? I just need to manually wipe and re-register my dependencies every time a test runs

hmlongco commented 10 months ago

May need versions of Xcode, Factory, etc. Not seeing this in demo tests...

@MainActor
final class FactoryDemoTests: XCTestCase {

    private let container = Container.shared // Here's the warning

    override func setUpWithError() throws {
        container.manager.reset()
    }