Swift: Value of type 'Published.Publisher' has no subscripts

Swift: Value of type 'Published.Publisher' has no subscripts
Value of type Published.Publisher has no subscripts

Issue

If you face Value of type 'Published<Text>.Publisher' has no subscripts error, then you are probably trying to access the variable wrong way. The API has changed since beta when it was first released - a lot has changed since then, causing the issues you're experiencing. With that being said, the breaking changes introduced is not difficult to resolve.

Solution

Depending on your use case you have to access the value with or without $sign , whether you want to access value or binding.

import SwiftUI

class SomeClass: ObservableObject {
    @Published var someVariable: Text = "Hello World"
}

struct ContentView: View {
    
    @EnvironmentObject var someClass: SomeClass // This is your @Published var modals: [Modal] = []
 
    
    var body: some View {
        return ZStack {
            Text(someClass.someVariable) //  we're accessing a Text value
            AnotherView(bindingValue: $someClass.someVariable) // we're accessing a Binding<Text> value
        }
    }
}

SwiftUI Elements

You can find also the whole implementation in my opensource UI kit.

References