Chapter 24
Creating a Search Bar View and Working with Custom Binding
Previously, we showed you how to implement a search bar by reusing the UISearchBar
component of the old UIKit framework. Have you ever thought of building one from scratch? If you look at the search bar carefully, it's not too difficult to implement. So, let's try to build a SwiftUI version of search bar in this chapter.
Not only can you learn how to create the search bar view, we will show you how to work with custom binding. We've discussed binding before, but haven't showed you how to create a custom binding. Custom binding is particularly useful when you need to insert additional program logic while it's being read and write. On top of all that, you will learn how to dismiss the software keyboard in SwiftUI.
Figure 1 gives you an idea about the search bar we're going to build. The look & feel is the same as that of UISearchBar
in UIKit. We will also implement the Cancel button which only appears when the user starts typing in the search field.

To access the full content and the complete source code, please get your copy at https://www.appcoda.com/swiftui.