Post

Replies

Boosts

Views

Activity

Reply to SwiftUI sidebar not behaving as intended
Your code seems to work for me on macos 12.1beta, xcode 13.1, targets ios 15 and MacCatalyst macos 12. Tested on real devices, iPad and Mac. Here is my test code: import SwiftUI @main struct TestApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { var body: some View { NavigationView { List { NavigationLink(destination: ExploreView()) { Label("Explore", systemImage: "rectangle.3.group") } NavigationLink(destination: Text("ListView")) { // <-- for testing Label("Devices", systemImage: "list.bullet.below.rectangle") } } .listStyle(.sidebar) .navigationTitle("Orchard") ExploreView() } } } // for testing struct ExploreView: View { var body: some View { ZStack { Color.pink.ignoresSafeArea() Label("Devices", systemImage: "list.bullet.below.rectangle").foregroundColor(.white) } } }
Nov ’21
Reply to Data struct not working
Concur, you do not show enough of your code. So I can only guess at your issues. You use ContentView(orchard: Orchard[0]) in ContentView_Previews, note carefully the uppercase Orchard[0]. This is wrong, Orchard is a type not an instance and not an array. It should at least be lowercase, orchard[0]. The other error you get is because you have "var orchard: Orchard " outside of any function or View or class. You cannot declare a variable without initialising, if it's not part of a class/struct etc..
Oct ’21
Reply to Add Button
you could try something simple like this: struct ContentView: View { @State private var buttons = 0 var body: some View { // the button to add other buttons Button(action: { buttons += 1 } ) { Image(systemName: "plus.circle.fill").foregroundColor(.black) } // the added buttons ForEach(0..<buttons, id: \.self) { i in Button("button \(i)") { } } } }
Oct ’21