UISearchBar select all text

This can be accomplished using the standard UIResponder semantics. No need to dig down into the private view hierarchy of UISearchBar.

[[UIApplication sharedApplication] sendAction:@selector(selectAll:) to:nil from:nil forEvent:nil]

You can call this from anywhere, and the selectAll: selector will run the responder chain to see if any objects respond to it. Assuming your search bar is currently the first responder (if the user is typing in it), it will respond and the result will be all text selected. If not you can make it the first responder by calling becomeFirstResponder on the search bar.

[_mySearchBar becomeFirstResponder]
[[UIApplication sharedApplication] sendAction:@selector(selectAll:) to:nil from:nil forEvent:nil]

If you want the 'type to replace' functionality that selecting the text in the UITextField gives you (ie the extra tap on the cross is unacceptable), you can dig through the subviews of the UISearchBar to find the UITextField (or UISearchBarTextField) and select its text:

// need to select the searchBar text ... 
UITextField * searchText = nil;
for (UIView *subview in searchBar.subviews) 
{
    // we can't check if it is a UITextField because it is a UISearchBarTextField.
    // Instead we check if the view conforms to UITextInput protocol. This finds
    // the view we are after.
    if ([subview conformsToProtocol:@protocol(UITextInput)]) 
    {
        searchText = (UITextField*)subview;
        break;
    }
}

if (searchText != nil)
    [searchText selectAll:self];

In my case, the sending selectAll(_:) didn't work immediately after calling becomeFirstResponder.

I worked around it by waiting one runloop:

Swift 2:

dispatch_async(dispatch_get_main_queue()) {
    UIApplication.sharedApplication().sendAction(#selector(UITextField.selectAll(_:)), to: nil, from: nil, forEvent: nil)
}

Swift 3:

DispatchQueue.main.async(execute: {
    UIApplication.sharedApplication().sendAction(#selector(UITextField.selectAll(_:)), to: nil, from: nil, forEvent: nil)
})