SwiftUI Example Which controls are needed

Like the screenshot of the apple developer app: How do I in my app add a serch box at the top of the sidebar option in SwiftUI? Also how do I add an account link at the bottom of the sidbar?

Accepted Reply

Welcome to the forum.

You will find a lot of tutorials on how to implement a searchBar.

What is it you don't succeed in doing ? What is your present code ?

Please show the code that will help giving more precise answer But principle is really simple:

struct ContentView: View { // This view is the side view
    @State var searchText = ""
    var data = [1,2,3,4,5,6,7,8,9,10]
    
    var body: some View {
        NavigationStack {
            ScrollView(.vertical) {
                ForEach(data, id: \.self) { d in
                    if searchText.isEmpty || String(d) == searchText {
                        Text("\(d)")
                    }
                }
            }
            .navigationTitle("Search")
            .searchable(text: $searchText)
        }
    }
    
}

Replies

Welcome to the forum.

You will find a lot of tutorials on how to implement a searchBar.

What is it you don't succeed in doing ? What is your present code ?

Please show the code that will help giving more precise answer But principle is really simple:

struct ContentView: View { // This view is the side view
    @State var searchText = ""
    var data = [1,2,3,4,5,6,7,8,9,10]
    
    var body: some View {
        NavigationStack {
            ScrollView(.vertical) {
                ForEach(data, id: \.self) { d in
                    if searchText.isEmpty || String(d) == searchText {
                        Text("\(d)")
                    }
                }
            }
            .navigationTitle("Search")
            .searchable(text: $searchText)
        }
    }
    
}

First of all thank you so much for giving me the right direction. I am just starting my journey into SwiftUI, swift and mac os x development. What I am now looking at is how to do the account link at the bottom of the sidebar.

@Claude31