UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Search box suggestions overlay views in SwiftUI

Forums > SwiftUI

Hi! I'm looking for a way to create search field with suggestions. Best example of it is location search in Maps.app in macOS Big Sur (pictured below).

I fail to create a view in SwiftUI that is laid out above other views, including search input focus indicator that shines through when i'm adding another overlay to view with .overlay() or positioning view on top of all others using ZStack I'm quite new to this and it doesn't seem straight-forward to build.

Not looking for a complete solution, just couple pointers in correct direction might be enough.

bigsur-maps

2      

If you subscribe to HWS+(PS it free for three days) then this is good place for a search field Creating a FilteringList to filter a list using text input

if not then another solution is Embrace Swift type inference. It talks about type inference but uses a example of a search box. A good talk anyway.

or look at this post SOLVED: Filter whole custom JSON object for SearchBarView

2      

Thanks @NigelGee for your response. However, i forgot to clarify that the problem i have is with view layout and positioning the suggestions box below the search field but on top of any other view in the window. The links you provided deal with wiring views together to data source and at least i think i understand this part :) But thanks anyway!

2      

Do you not put the search field and content below in a ZStack to put one view on top another

2      

Sorry my understanding was about the search as this is not build into swift. If you are talking about the View under showing though the top View you need to look at the background and opacity of it as 0 is full clear and 1 (default) is solid.

2      

Fwiw, managed to build working solution for this by following the ideas from https://github.com/smic/SuggestionsDemo

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.