Avatar
import SwiftUI extension View { func onAppear2(_ perform: @escaping () -> Void) -> some View { OnAppearView(content: self, perform: perform) } } private struct OnAppearView<Content>: UIViewControllerRepresentable where Content: View { let content: Content let perform: () -> Void func makeUIViewController(context: Context) -> OnAppearViewController<Content> { OnAppearViewController(content: content, perform: perform) } func updateUIViewController(_ viewController: OnAppearViewController<Content>, context: Context) { viewController.rootView = content } } private final class OnAppearViewController<Content>: UIHostingController<Content> where Content: View { let perform: () -> Void init(content: Content, perform: @escaping () -> Void) { self.perform = perform super.init(rootView: content) view.backgroundColor = .clear } @objc required dynamic init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) perform() } } ワークアラウンド思い付きました。 onAppear の代わりに↑の onAppear2 を使えば回避できました。