I have the same error in a newly created project.
macOS 15.0.1
Xcode 16.0 (16A242d)
Post
Replies
Boosts
Views
Activity
Use onDismiss view modifier in your SettingsView.
This is working approach:
import SwiftUI
import WebKit
struct YouTubeView: NSViewRepresentable {
let webView: WKWebView
let link: String
init(link: String) {
let configuration = WKWebViewConfiguration()
configuration.preferences.isElementFullscreenEnabled = true
let webView = WKWebView(frame: .zero, configuration: configuration)
webView.translatesAutoresizingMaskIntoConstraints = true
webView.autoresizingMask = [.width, .height]
webView.allowsBackForwardNavigationGestures = false
self.webView = webView
self.link = link
}
func makeNSView(context: Context) -> NSView {
return NSView()
}
func updateNSView(_ nsView: NSView, context: Context) {
nsView.translatesAutoresizingMaskIntoConstraints = true
nsView.addSubview(webView)
guard let url = URL(string: link.embed) else { return }
webView.load(.init(url: url))
}
}
// Build youtube link
extension String {
var embed: String {
var strings = self.components(separatedBy: "/")
let videoId = strings.last ?? ""
strings.removeLast()
let embedURL = strings.joined(separator: "/") + "/embed/\(videoId)"
return embedURL
}
}
Did you resolve these problem? I have same issues in Xcode 14.3.
Hi! Have you found a solution?