Replies: 1 comment 2 replies
-
Hi @hayek, the error you are seeing should only happen when setting the value. Not when merely accessing the value. This code compiles just fine for me: func foo() -> Int {
@Shared(.inMemory("favorites")) var favorites = [42]
return favorites[0]
} Can you share some code that produces a compilation error from only accessing the state? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Given a shared collection such as an Array, the only way to access it's elements by using a subscript is by casting:
Having an extension to wrap the subscript in a function also works:
The reason behind this error is that the Sharing framework utilizes dynamic member lookup's subscript to surface the value of the wrapped reference.
Is there any solution in swift to enable both dynamic member lookup and subscripts of types to work without the workarounds I mentioned?
Beta Was this translation helpful? Give feedback.
All reactions