Skip to content

Adding an Icon to the Navigation Bar, moving from Introspect to SwiftUIIntrospect #325

Closed Answered by davdroman
antonnyman asked this question in Q&A
Discussion options

You must be logged in to vote

The crash is:

Thread 1: "Unable to activate constraint with anchors <NSLayoutXAxisAnchor:0x60000178b180 \"_TtGC7SwiftUI14_UIHostingViewV8Showcase14ProfilePicture_:0x10e73aec0.trailing\"> and <NSLayoutXAxisAnchor:0x60000178b1c0 \"_TtGC7SwiftUI19UIHosting.trailing\" (names: _TtGC7SwiftUI19UIHosting:0x10ea119e0)> because they have no common ancestor.  Does the constraint or its anchors reference items in different view hierarchies?  That's illegal."

This happens when the view you're trying to constrain is nowhere to be found in the hierarchy.

The problem is in this line:

bar.subviews.first(where: \.clipsToBounds)?.addSubview(hostingView)

Notice the ?. That line can be a no-op, and that's ho…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@davdroman
Comment options

Answer selected by antonnyman
Comment options

You must be logged in to vote
1 reply
@davdroman
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants