UISearchBar's set_cancelButtonText: ivar is prohibited
Instead of messing around with the undocumented view hierarchy, you can use UIAppearance
:
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).title = "Whatever"
Objective-C version:
[[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTitle:@"CancelText"];