The Hype to Swift 3.0 Tutorial Series is Finished!

Thanks, Nick, I appreciate your time. I’ve kind of been pulling my hair out over this. Documentation is trying to push folk from UIWebView to WK WebView, so I thought I’d give it a try. But, while webview is fairly straightforward, WKWebView, as you’ve mentioned, is much less so.

With your code, for the baseUrl, I’m unclear how to write the string. Say I have a folder, called Project, that I’ve copied into my xcode. Inside Project is my project.html file and its resource folder, called Folder. How would I define the string? I seem to be labeling things incorrectly because it’s still not seeing the resources.


Hmm.. I have not seen this issue and have used wkwebview in the past with no issues

I just did a convert on the project to use modernised swift syntax and update to modern Xcode.
Apart from Xcode throwing up some errors about some notifications syntax. Which can be ignored , just rerun build and they go away Xcode seems to jst want me to wast my time writing the line again.
All still works .

The whole swift file contains

//  ViewController.swift
//  iOSHypeCalls
//  Created by Mark Hunte on 18/09/2016.
//  Copyright © 2016 Mark Hunte. All rights reserved.

import UIKit
import WebKit
class ViewController: UIViewController {
    @IBOutlet var containerView : UIView! = nil
    var webView: WKWebView?
    override func loadView() {
        NotificationCenter.default.addObserver(self, selector: #selector(enterBackground), name: NSNotification.Name("UIApplicationWillResignActiveNotification"), object: nil)
 NotificationCenter.default.addObserver(self, selector: #selector(exitBackground), name:NSNotification.Name("UIApplicationWillEnterForegroundNotification"), object: nil)
 self.webView = WKWebView(frame: self.view.bounds)
        self.view = self.webView!
    override func viewDidLoad() {
        let theUrl = Bundle.main.url(forResource: "testCall", withExtension:"html")
        let req = NSURLRequest(url: theUrl!)
        self.webView!.load(req as URLRequest)

    func enterBackground()  {
        print("call 1")
         self.webView!.evaluateJavaScript("HYPE.documents['testCall'].showSceneNamed('splashScene', HYPE.documents['testCall'].kSceneTransitionCrossfade, 0.2);", completionHandler:nil )
    func exitBackground()  {
        print("call 2")
        self.webView!.evaluateJavaScript("HYPE.documents['testCall'].showSceneNamed('scene1', HYPE.documents['testCall'].kSceneTransitionCrossfade, 3);", completionHandler:nil )
    override func didReceiveMemoryWarning() {
        // Dispose of any resources that can be recreated.

And as you can see I do not have to massage the url !.

The one thing I notice is that I use NSURLRequest where you do not..
In mine I make sure I am using URLs and not strings.

 override func viewDidLoad() {
        let theUrl = Bundle.main.url(forResource: "testCall", withExtension:"html")
        let req = NSURLRequest(url: theUrl!)
        self.webView!.load(req as URLRequest)

Thanks. In this, I’m looking for an alternative for #selector(enterBackground), as my Xcode is not liking the enterBackground. Swift keeps changing, which I guess is a good thing/frustrating thing. :wink:


That was the notification my Xcode flagged when I updated the project. But I just ignored it and did a Run Build.
The warnings just went away ?

But remember the #selector(enterBackground) notification is only used in this as an example to show communication between iOS and the Hype API

Here is the re-built project. Done in Xcode Version 8.3.1 (8E1000a).

iOSHypeCalls (291.0 KB)


Thanks for the insight Mark!
I will give this a go tonight and prepare another addendum to the video tutorials.
I have been working off and on with the Android version as well as prototyping templates for iOS and Android in Hype…now that I understand how to load SanFrancisco fonts
Thanks @Daniel !


Wow, thanks, Mark. You’ve made use of the evaluateJavaScript thing, here. I had been looking at that, thinking it might make sense, but wasn’t sure how to implement it. And you have created an enterBackground function. For some reason when I had tried that, I ended up with a new error. Going to have to recheck my typing.

Thanks again!

This really is one of the best forums, due in great part to folk like you both.



I don’t know if anyone else already encountered this problem, so here I go.
Until now everything worked smoothly and I’d like to thank @nick for his excellent tutorial. But we have Xcode 9 now and my earlier projects don’t work anymore because of: Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0). This warning comes after the line: let myRequest = NSURLRequest(url: localfilePath!);
and also: fatal error: unexpectedly found nil while unwrapping an Optional value
I can’t seem to fix it. Do you have a solution?

I just converted my example above. I do not get this.

Can you post a small example project where you get this…

I just created this new one. same (25.0 KB)

hold on. I was to quick.

I forgot the HTML files :joy:, but it doesn’t make any difference.rotating (26.2 KB)

you still forgot the html files. But I just added my own.

I suspect that the issue is that the html index.html and the hyperesources folder have not been added to the ‘Copy Bundle Resources’ in the build phase for the project.

Add the two items to it if not.

Sorry, I don’t get it. I have done it this way for some time now and all over sudden it stops working. I already have a test version off the app in the App Store. Here is a screenshot of the ‘error’. And where would I find "Copy Bundle Resources’?

I just tried Nick’s Saniteyes and it works. All my work is based on his code, so…?

1, Click the project file.

2, Select the Target file.

3, Go to the build phase

4, Down to the Copy Bundle Resources

Check if the items are in there.

5, If not click the add button, select them both from the list that appears and add them.


Wow, that did the trick. I’m pretty sure I haven’t done this before, so a change in Xcode9?

I will buy you a beer :beer:
No, make it 2 :beers:

Thanks a lot Mark



I do not think it is a change. It just seems to happen sometimes


Working on the new update video today for Xcode 9.0 should be done by days end.
I will post in the forums and back on Youtube.

Dont ya just love progress in code :wink:



While working on this I found out it is a bug in Xcode 9.0
It should not happen especially if you check your “Add to Targets” box.
I have tried it now several different ways and the best way is the manual Copy Bundle Resources.

Video will point this out…and I hope they fix it because while it is not that much of a lift you would expect it to copy automatically.


Good catch, I was sure I did have that checked when I added mine in the test.
It’s what threw me for a bit and I went through a few things before I checked the copy… and then doubted myself on it.

1 Like

The tutorial for Xcode 9 is live!