SuggestionTextFieldMenu-SwiftUI

My project about a suggestion field in swiftUI

This is how it looks like!

ezgif com-video-to-gif-2

You can fill an array of objects and decide how many lines you want to show. I decided to show just a max of 3 lines and reduce them one by one through the filter.

So let’s start from the beginning!

First of all, I created a struct that will contain my universal component. Declare the variables that you need, in this case, I declared these:

@Binding var editing: Bool

@Binding var inputText: String

@State var verticalOffset: CGFloat

@State var names: [String] = []
 
@State var horizontalOffset: CGFloat

after i decided to filter my array in that way:

<div class="snippet-clipboard-content position-relative" data-snippet-clipboard-copy-content="private var filteredTexts: Binding { Binding (
get: {
return names.filter { $0.contains(inputText) && $0.prefix(1) == inputText.prefix(1) } },
set: { _ in })
}
“>

private var filteredTexts: Binding<[String]> { Binding (
    get: {
        return names.filter { $0.contains(inputText) && $0.prefix(1) == inputText.prefix(1) } },
    set: { _ in })
}