As a beginner I'm trying to learn to properly navigate Apple's API documentation while studying a tutorial book as assistance. While following an example on programmatic constraints, I came across the following method:
let leadingConstraint = segmentedControl.leadingAnchor.constraint(equalTo: <NSLayoutAnchor<NSLayoutXAxisAnchor>)
I've learned that angle brackets signify a generic. However is this what Apple is implying by using angle brackets in this situation? While searching the documentation on NSLayoutAnchor, I couldn't find "topAnchor" similar to how the following code has:
let topConstraint = segmentedControl.topAnchor.constraint(equalTo: view.topAnchor)
How can I find out what are the choices for the generic type called "AnchorType"? Or am I looking at the context incorrectly?
Thank you in advance.
The first example you give is invalid code (the lack of balanced angle brackets, for one). However, I think I understand what it might be trying to explain.
Apple's documentation for
NSLayoutXAxisAnchor(see https://developer.apple.com/documentation/uikit/nslayoutxaxisanchor) has a similar example to your second.In this the documentation explains that the types of the anchors need to match. In the line
both
leadingAnchorandtrailingAnchorare X axis anchors and the code is good.In the second example
topAnchoris a Y Axis anchor, so a warning is generated.NSLayoutXAxisAnchoris derived fromNSLayoutAnchor, so I think the first example you give is attempting to get across the idea that the parameter needs to be aNSLayoutAnchorthat is actually aNSLayoutXAxisAnchor.The documentation for
NSLayoutAnchor(see https://developer.apple.com/documentation/uikit/nslayoutanchor) gives the possibilities:NSLayoutXAxisAnchorNSLayoutYAxisAnchorNSLayoutDimension