Hello everyone,
I am currently working on integrating a WebView into my macOS application, intended to allow users to browse tutorial webpages directly within the app.
Although I’ve followed an example that appears syntactically correct, the WebView does not render any webpage content.
Below is a code snippet for reference:
import SwiftUI
import WebKit
struct HelpWebView: View {
@State private var toggle = false
@State private var page = WebPage()
private var url: URL {
toggle
? URL(string: "https://www.webkit.org")!
: URL(string: "https://www.swift.org")!
}
var body: some View {
WebView(page)
.onAppear {
page.load(URLRequest(url: url))
}
.onChange(of: toggle) {
page.load(URLRequest(url: url))
}
.toolbar {
Button("Reload", systemImage: "arrow.clockwise") {
toggle.toggle()
}
}
}
}
I would greatly appreciate any insights or suggestions on what might be causing this issue or how to resolve it.
Thank you in advance for your help!
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hello everyone,
I am currently working on integrating a WebView into my macOS application, intended to allow users to browse tutorial webpages directly within the app.
Although I’ve followed an example that appears syntactically correct, the WebView does not render any webpage content.
Below is a code snippet for reference:
import SwiftUI
import WebKit
struct HelpWebView: View {
@State private var toggle = false
@State private var page = WebPage()
private var url: URL {
toggle
? URL(string: "https://www.webkit.org")!
: URL(string: "https://www.swift.org")!
}
var body: some View {
WebView(page)
.onAppear {
page.load(URLRequest(url: url))
}
.onChange(of: toggle) {
page.load(URLRequest(url: url))
}
.toolbar {
Button("Reload", systemImage: "arrow.clockwise") {
toggle.toggle()
}
}
}
}
I would greatly appreciate any insights or suggestions on what might be causing this issue or how to resolve it.
Thank you in advance for your help!
Hi,
I am currently developing a document-based application with additional WindowGroup for macOS and have encountered a challenge related to document container management. Specifically, I need to open a windowGroup that shares the same container as the one used in the DocumentGroup. However, my current approach of using a global shared model container has led to unintended behavior: any new document created is linked to existing ones, and changes made in one document are reflected across all documents.
To address this issue, I am looking for a solution that allows each newly created document to be individualized while still sharing the document container with all relevant WindowGroups that require access to the data it holds. I would greatly appreciate any insights or recommendations you might have on how to achieve this.
struct Todo: App {
var body: some Scene {
DocumentGroup(editing: Item.self, contentType: .item) {
ContentView()
}
WindowGroup(for: Item.self) { $item in
ItemView(item:$item)
.modelContainer(Of DocumentGroup above)
}
}
}
Thank you for your time and assistance.
Best regards,
Hi,
I am currently developing a document-based application for macOS and have encountered a challenge related to document container management. Specifically, I need to open a windowGroup that shares the same container as the one used in the DocumentGroup. However, my current approach of using a global shared model container has led to unintended behavior: any new document created is linked to existing ones, and changes made in one document are reflected across all documents.
To address this issue, I am looking for a solution that allows each newly created document to be individualized while still sharing the document container with all relevant WindowGroups that require access to the data it holds. I would greatly appreciate any insights or recommendations you might have on how to achieve this.
Thank you for your time and assistance.
Best regards,
Something like:
@main
struct Todo: App {
var body: some Scene {
DocumentGroup(editing: Item.self, contentType: .item) {
ContentView()
}
WindowGroup {
UndockView()
.modelContainer(of documentGroup above)
}
}
}