Skip to content
No description, website, or topics provided.
Swift HTML Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

HIPWebApp: WKWebView design patterns

Swift 3.x

Docs (you may already be here)


HIPWebApp is a set of protocols and classes for Swift and iOS that removes a lot of boilerplate from the process of creating and configuring a WKWebView. It encourages you to create a dedicated "web app" object whose only job is to be the interface between your web code and your native code.

At Hipmunk, we've been experimenting with ways to integrate web-based views into our app without providing a bad experience for users. To us, that means tight integration between the code running in the web view and the native parts of our app. Using this pattern has helped us do that without leaving behind a pile of spaghetti code.

The source code comes with a few examples.

Installation with Carthage

Add this line to your Cartfile:

github "hipmunk/HIPWebApp" ~> 1.0


First, make a class that implements WebApp. The only hard requirements are a string identifier for logging (appIdentifier) and an initial URL.

import Foundation
import HIPWebApp

class SimplestExampleWebApp: WebApp {
    let appIdentifier = "google"
    let initialURL = NSURL(string: "")!

Then you need a subclass of WebAppViewController to host it. Here is the minimum viable subclass:

import UIKit
import HIPWebApp

class SimplestExampleWebAppViewController: WebAppViewController {

    override func createWebApp() -> WebApp { return SimplestExampleWebApp() }

    override func viewDidLoad() {
        // optional: set self.WebAppViewControllerLoggingDelegate to enable logging




You are now done!

If you want to do more, you'll need to implement one or more of these protocols:

  • WebAppWebViewReferencing gives you an opportunity to store a reference to the web view. While this is a very common thing to do, it isn't strictly necessary.
  • WebAppConfiguring lets you provide a WKWebViewConfiguration, meaning you can add user scripts and more.
  • WebAppNavigating lets you provide a navigation delegate.
  • WebAppMessageHandling lets you listen for calls to messageHandlers[messageName].postMessage(messageBody).

See HIPWebApp/WebApp.swift and HIPWebAppDemo/Examples for details.


Here is a potentially helpful diagram about how the different classes and protocols are related.

class diagram

Further reading

Release history


Made WebAppViewController.webViewContainer public


Update to Swift 2.3


Initial release.

You can’t perform that action at this time.