Saturday, November 21, 2026
HomeiOS Developmentios - i cant despatched the delegate of the UI search Bar...

ios – i cant despatched the delegate of the UI search Bar in computed property

[ad_1]

I just lately got here throughout one thing bizarre that i am unable to wrap my head round.

i used to be utilizing a SearchBar as a UI ingredient. (observe: it’s the UIView subclass and never UIViewController subclass that apple handily offers out.

However i wasn’t in a position to assign the the delegate within the computed property however was in a position to in viewDidload().

@usesAutoLayout var imageSearchbar:UISearchBar = {
    let bar = UISearchBar()
    bar.delegate = self
    bar.searchBarStyle = .minimal
    bar.searchTextField.backgroundColor = .white
    return bar
}()

bar.delegate = self reveals a compile time error


Can’t assign worth of kind ‘(CollectionViewController) -> () ->
CollectionViewController’ to kind ‘UISearchBarDelegate?’


I wish to achieve data as to what’s it that i am lacking.
Assist appreciated.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments