Top layout guide is deprecated in iOS 11
The Obj-C version:
[[searchBackView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor constant:0] setActive:YES];
If you have translucent bars note: then the topLayoutGuide is below the bar, e.g the statusBar.
see: topLayoutGuide It explains conditions which is important to consider.
Whereas the safeAreaLayoutGuide.topAnchor would not be beneath the NavigationBars; much simpler to work with.
TopLayoutGuide is deprecated in iOS 11 so we have option to use SafeAreaLayoutGuide like this :
- First we can get view safeAreaLayoutGuide
let guide = view.safeAreaLayoutGuide
Second add constraint to guide
searchBackView.topAnchor.constraint(equalTo: guide.topAnchor).isActive = true