My Application has a modal view controller, including a search bar. When the view comes up, I want the search bar to be focused. I tried [self.searchBar becomeFirstRespond
You should call in viewDidLayoutSubviews(), the code below set textField becomeFirstResponder only at the first time view layout subviews, and it should be.
var isFirstLayout: Bool = true
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if isFirstLayout {
defer { isFirstLayout = false }
textField.becomeFirstResponder()
}
}