Value of type 'Text' has no member 'searchable'

I want to use searchbar for name, but it is throw an arror like " Value of type 'Text' has no member 'searchable'" any idea?

  @State private var searchText = ""
   Text(data.name)
                .font(.custom("Helvetica Neue", size: 14))
                .searchable(text: $searchText)
Answered by Claude31 in 683597022

You can use conditional statement :

                if #available(iOS 15.0, *) {
                   Text(data.name)
                      .font(.custom("Helvetica Neue", size: 14))
                     .searchable(text: $searchText)
                } else {
                   Text(data.name)
                      .font(.custom("Helvetica Neue", size: 14))
                }

Are you using Xcode 13?

no last version Version 12.5.1

That's only available for iOS 15, hence Xcode 13.

Accepted Answer

You can use conditional statement :

                if #available(iOS 15.0, *) {
                   Text(data.name)
                      .font(.custom("Helvetica Neue", size: 14))
                     .searchable(text: $searchText)
                } else {
                   Text(data.name)
                      .font(.custom("Helvetica Neue", size: 14))
                }
Value of type 'Text' has no member 'searchable'
 
 
Q