How to solve official guide of interfacing SwiftUI with UIKit's bug?

I'm following official guide of https://developer.apple.com/tutorials/swiftui/interfacing-with-uikit for SwiftUI, this tutorial wraps `UIPageViewController` with SwiftUI.


I found that when `PageView` is only given with an array of ONE element, such as


PageView([FeatureCard(landmark: features[0])])


Then when I turn the page, the image disappears.

Replies

If I remember well, that's the usual behavior of PageView.

It first remove the existing page, then displays the next.

If you have a single page, nothing to show.


You should test for the array being a single element and disable the turnPage.

Or create a dummy next page just to say "no more"

In fact, in its viewController's Coordicator's `func pageViewController(_:, viewControllerBefore:)` and `func pageViewController(_:, viewControllerAfter:)` method, this tutorial (Section 2, Step 3) checks the next page and makes the page controller a circular one, which means the next page of last page is the first page, and the previous page of the first page is the last page. So I don't think this bug behavior is related to the usual behavior of UIPageView.