79816041

Date: 2025-11-10 20:32:42
Score: 0.5
Natty:
Report link

If you want to avoid @MainActor annotation you could use @unchecked Sendable annotation at class level to tell compiler you will be managing. Usually Net handlers are only one per app process so it will be safe.

In the line:

try await self.onNetworkStateChanged(networkConnectionState: state)

Try using an eternal reference for your net manager and avoid weak self

    private func setupNetworkMonitoring() async {

        let netManager = self
        await networkMonitor.startMonitoring { state in
            guard let self = self else { return }
            Task {
                // ⬇ ⬇ ⬇ Capture of 'self' with non-sendable type 'NetworkService' in a `@Sendable` closure
                try await netManager.onNetworkStateChanged(networkConnectionState: state)
            }
        }
    }
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @MainActor
  • User mentioned (0): @unchecked
  • Low reputation (0.5):
Posted by: blacktiago