Swiftpack.co - kylehickinson/SwiftUI-WebView as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by kylehickinson.
kylehickinson/SwiftUI-WebView 0.3.0
A SwiftUI component to use WKWebView
⭐️ 241
🕓 3 days ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/kylehickinson/SwiftUI-WebView.git", from: "0.3.0")


A SwiftUI component View that contains a WKWebView

Since WKWebView handles a lot of its own state, navigation stack, etc, it's almost easier to treat it as a mutable data model. You can set it up prior to how you need it, and then simply use its data within your SwiftUI View's.

Simply spin up a WebViewStore (optionally with your own WKWebView) and use that to access the WKWebView itself as if it was a data model.

Example usage:

import SwiftUI
import WebView

struct ContentView: View {
  @StateObject var webViewStore = WebViewStore()
  var body: some View {
    NavigationView {
      WebView(webView: webViewStore.webView)
        .navigationBarTitle(Text(verbatim: webViewStore.title ?? ""), displayMode: .inline)
        .navigationBarItems(trailing: HStack {
          Button(action: goBack) {
            Image(systemName: "chevron.left")
              .aspectRatio(contentMode: .fit)
              .frame(width: 32, height: 32)
          Button(action: goForward) {
            Image(systemName: "chevron.right")
              .aspectRatio(contentMode: .fit)
              .frame(width: 32, height: 32)
    }.onAppear {
      self.webViewStore.webView.load(URLRequest(url: URL(string: "https://apple.com")!))
  func goBack() {
  func goForward() {


Stars: 241
Last commit: 3 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Related Packages

Release Notes

1 year ago
  • Adds macOS Support (#2)
  • Adds @dynamicMemberLookup to WebViewStore for a shortcut to the underlying WKWebView's properties
  • Adds license (#1)
  • Removes unnecessary view container in UI/NS view representables

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics