I have a UIPageViewController that's wrapped up into a SwiftUI view. The view is instantiated with a @Binding value:
PageView([Text("Hello")], currentPage: $page)
I have some internal state that I'd like to change based on the incoming @Binding variable.
@State var currentPageIndex: Int
@State var goRight: Bool?
public var currentPage: Binding<Int> {
Binding(
get: {
return self.currentPageIndex
},
set: {
self.goRight = ((self.currentPageIndex - $0) > 0)
self.currentPageIndex = $0
}
)
}
When I try to set the UIPageViewController based on this index,
pageViewController.setViewControllers([controllers[currentPage]], direction: .forward, animated: true)
this line fails with the error Cannot convert value of type 'Binding<Int>' to expected argument type 'Int'
Yet when I simply use a @Binding value without doing anything to it,
@Binding var currentPage: Int
everything compiles just fine. I understand the core of this issue to be, there's some sort of difference between @Binding var blah: Int and var blah: Binding<Int> Why is this the case? Why is there something else I have to do to access the underlying value of a type Binding<Int>? I understand these things to be two different ways of saying the same thing. Or are they not equivalent?