Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewFactory should be @MainActor constrained #722

Open
swizzlr opened this issue Jan 17, 2025 · 1 comment
Open

ViewFactory should be @MainActor constrained #722

swizzlr opened this issue Jan 17, 2025 · 1 comment
Labels

Comments

@swizzlr
Copy link

swizzlr commented Jan 17, 2025

What are you trying to achieve?

I have views that depend on MainActor isolated view models. In order to initialize my views I need to retrieve these MainActor isolated dependencies that are retrieved via "@Inject" in the viewfactory. Since the viewfactory methods are nonisolated, I'm not able to access these - and if I annotate the methods as @mainactor, they do not satisfy the protocol requirements.

If possible, how can you achieve this currently?

Maybe I could try injecting them directly into the views?

What would be the better way?

Since SwiftUI Views are MainActor isolated to begin with, and the ViewFactory is invoked from Views in a MainActor isolated context, it seems reasonable to constrain the ViewFactory to MainActor

GetStream Environment

GetStream Chat version: 4.61
GetStream Chat frameworks: StreamChat, StreamChatSwiftUI
iOS version: any
Swift version: 6
Xcode version: 16.2
Device: any

Additional context

n/a

@laevandus
Copy link
Contributor

Hi @swizzlr,

We'll review it internally and will get back to you. Adding a @mainactor requirement might cause a breaking change for SDK users, therefore it needs to be considered carefully.

Thank you,
Toomas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants