An observable representation of a webpage's previously loaded resources.
This type can be used to facilitate navigating to prior or subsequent loaded resources
and for observing when new entries get added or removed.
In this example, the back-forward list is used to create a SwiftUI View to facilitate navigating to
previous or next items:
```swift
private struct BackForwardMenuView: View {
struct LabelConfiguration {
let text: String
let systemImage: String
}
let list: [WebPage.BackForwardList.Item]
let label: LabelConfiguration
let navigateToItem: (WebPage.BackForwardList.Item) -> Void
var body: some View {
Menu {
ForEach(list) { item in
Button(item.title ?? item.url.absoluteString) {
navigateToItem(item)
}
}
} label: {
Label(label.text, systemImage: label.systemImage)
.labelStyle(.iconOnly)
} primaryAction: {
navigateToItem(list.first!)
}
.disabled(list.isEmpty)
}
}
```
The view can then be used for both the back and forward list using a specific ``WebPage``:
```swift
struct ContentView: some View {
@State private var page = WebPage()
var body: some View {
WebView(page)
.toolbar {
ToolbarItemGroup {
ToolbarBackForwardMenuView(
list: page.backForwardList.backList.reversed(),
label: .init(text: "Backward", systemImage: "chevron.backward")
) {
viewModel.page.load($0)
}
ToolbarBackForwardMenuView(
list: page.backForwardList.forwardList,
label: .init(text: "Forward", systemImage: "chevron.forward")
) {
viewModel.page.load($0)
}
}
}
}
}
```
Because ``WebPage/backForwardList`` is an observable property, the states of these buttons
are automatically updated.
Members (4)
get · iOS 26.0+
backList
TypeScript
get backList(): Promise<Array<WebPage_BackForwardList_Item>>
Swift declaration
@MainActor var backList: [WebPage.BackForwardList.Item] { get }
The array of items that precede the current item.
The items are in the order in which the page originally visited them.
get · iOS 26.0+
forwardList
TypeScript
get forwardList(): Promise<Array<WebPage_BackForwardList_Item>>
Swift declaration
@MainActor var forwardList: [WebPage.BackForwardList.Item] { get }
The array of items that follow the current item.
The items are in the order in which they were originally visited.
get · iOS 26.0+
currentItem
TypeScript
get currentItem(): Promise<(WebPage_BackForwardList_Item) | null>
Swift declaration
@MainActor var currentItem: WebPage.BackForwardList.Item? { get }
The current item.
When the webpage has not loaded any resources, this value will be `nil`.
@MainActor subscript(index: Int) -> WebPage.BackForwardList.Item? { get }
Accesses the item at the relative offset from the current item.
- Parameter index: The offset of the desired item from the current item. Specify `0` for the current item,
`-1` for the immediately preceding item, `1` for the immediately following item, and so on.
- Returns: The item at the specified offset from the current item, or `nil` if the index exceeds the limits of the list.