Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

how to get subviews of a SwiftUI view in UIKit environment

I have a SwiftUI view that I have wrapped using UIHostingController for use within UIKit.

Requirement: Within the UIKit environment, I want to get all the subviews of this SwiftUI view and determine whether the images within those subviews have finished loading.

For UIKit views, we can use view.subviews to get all the subviews and do the check.

However, for SwiftUI views, I found that the view.subviews turns out to be an empty array, making it impossible to do further checks.

So the question is How can I get the subviews of a SwiftUI view?

AFAIK, it is not possible for views outside of the UIKit UIHostingController.

In fact views in SwiftUI are very different, they are just drawn when needed.

See discussion here: https://www.reddit.com/r/SwiftUI/comments/1kq7aop/how_to_get_subviews_of_a_swiftui_view_in_uikit/

But you wrote

SwiftUI view that I have wrapped using UIHostingController

So where's the problem ?

Requirement: Within the UIKit environment, I want to get all the subviews of this SwiftUI view and determine whether the images within those subviews have finished loading.

A way to handle this would be from the data layer. That means passing a shared Observable Object into your SwiftUI view so the object can push updates that SwiftUI reacts to automatically, while SwiftUI updates the properties with its own state changes (e.g., when an image finishes loading) through the same object for UIKit to observe.

how to get subviews of a SwiftUI view in UIKit environment
 
 
Q