P. 111 "topLayoutGuide"


#1

According to XCode, “topLayoutGuide” is depricated as of iOS 11.0. Developer documentation says to use safeAreaLayoutGuide instead.


#2

I experienced the same with IOS 11.0 and additionally the margin.leadingAnchor
does not work.
So I replaced
let leadingConstraint =
segmentedControl.leadingAnchor.constraint(equalTo: margins.leadingAnchor)
with
let leadingConstraint = segmentedControl.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20)
and -20 for the trailingAnchor


#4

@Orangecicle I was able to implement safeAreaLayoutGuide using the following code:

// the top anchor of the segmented control should be 8 points below the top of the view’s safeAreaLayoutGuide

let topConstraint = segmentedControl.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 8)

@katiekalt I had the problem with the topLayoutGuide not working with iOS 11.0, but I didn’t have any problems with the margins.leadingAnchor. Typo perhaps? Is my first line in your code as well?

Here’s my code, same as in the book:

let margins = view.layoutMarginsGuide
let leadingConstraint = segmentedControl.leadingAnchor.constraint(equalTo: margins.leadingAnchor)
let trailingConstraint = segmentedControl.trailingAnchor.constraint(equalTo: margins.trailingAnchor)