Solved: BullsEye - Webview with Error (Ressource-Path?) [always make the connections in interface builder]

Bulls-Eye-Tutorial: Chapter 7 - Testing after adding Webview

If I click to get to the AboutScreen get the Error:

fatal error: unexpectedly found nil while unwrapping an Optional value
2017-10-30 13:45:19.645864+0100 Bulleye-Tutorial[40141:4016474] fatal error: unexpectedly found nil while unwrapping an Optional value

In this line of AboutViewController:

webView.load(htmlData, mimeType: “text/html”,
textEncodingName: “UTF-8”, baseURL: baseURL)

My step 1:
to exclude typos I replaced my code with the provided code - but no difference.

I think that the error means that the ressoucre bullseye.html is not found in the specified location.

My step 2:
So I double-checked that the ressource is imported. Comparing my version with the provided project shows no differences in the location of bullseye.html.

My step 3:
Run the provided projekt (chapter-07-final)
-now it compiles without error
but: The Webview shows just white - no text, it displays nothing

Any ideas? At least the provided project should show something?

It does indeed look as if the code is not loading the HTML file properly. One possibility is that while the file was added to the project, it is not marked as being part of the correct target. With the BullsEye.html file selected, can you please check the File inspector to see that the BullsEye target is checked under the Target Membership section?

I just checked the final project for the book and it appears that it to is missing the correct target membership. I could have sworn I tested this while writing the book but obviously, something went amiss :slight_smile: Sorry about that.

After checking the target in the provided project it now shows the html - so I have a base to continue.

In my project the target was checked. It seems there is something corrupt in my project file - I will start from chapter 6 again and see if it works - I will report back if the problem persists.

Thanks for the fast reply.

Glad to hear that you were at least able to get the base project working. If you still continue to experience issues with your own project, if you can ZIP it up and upload it somewhere like DropBox and provide a link here, I can take a look and see what is going on.

  1. I started again with chapter-06-final as base.
  2. I skipped all steps to make the app more pretty. Instead I added the 2nd view (AboutViewController)
  3. checked that I could switch between the 2 views
  4. I added the webView and copied the code for the AboutViewController to load “bullseye.html” from chapter 7
  5. same Error as described above

I zipped the project folder, it would be great if you could have a look!

I uploaded at my server. URL:


Will take a look as soon as I can. Unfortunately, had to hand my MacBook over to Apple due to hardware issues yesterday and so need to wait till it is repaired. So might take about a week (according to their estimates). Just letting you know - but will take a look and get back to you once I have the machine back.

In the mean time, if you want to debug the issue on your own, what you’d need to do would be to check if the line loading the data from the HTML file returns nil. If it does, then you know the issue is with reading the HTML file as data, if not, then the issue is elsewhere.

If the data is nil, then you need to figure out why it is nil. You can always check the final app, if you can find it in the simulator folder structure, to see if it contains the HTML file or if it is being missed out for some reason as a first step.

Hope this helps.

Thank you very much for the pointers! I found my mistake.

  1. drilled down the path of the file, found that It was there and not corrupted
  2. found out that you can search for “nil” in the debugger-area on the bottom of the xcode-window
  3. searched for “nil”, it shows that the “weak var webView: UIWebView” itself is nil
  4. I remembered this line from the book (page 107):

Don’t forget to make those connections
Forgetting to make the connections in Interface Builder is an often-made mistake, especially by yours truly.

  1. I forgot the connection of the viewcontroller to the webView in the storyboard

I compared the provided project with my error-showing-project but this difference escaped me.

So problem solved. Thanks again for taking the time and getting me on the right track to look for nil.

I’m happy to hear that you were able to sort out the issue on your own - if you hit a nil isues it’s generally either something not initializiatin properly or a connection which was not set up :slight_smile:

When I built the Bull’s Eye Final App using the provided Source Code, the Info button would not properly load the BullsEye.html file. The quick fix for me was to delete the BullsEye.html file from the project and then re-add the file by dragging it from the source to the project. Rebuild. Run.

I just tested and you are right. It appears that the BullsEye.html file is not included in the BullsEye target. Rather than removing the file from the project and re-adding it, you can also simply select the file, switch to the File inspector and check the box for the BullsEye target. It will show up correctly then.

Sorry about that :slight_smile:

This topic was automatically closed after 166 days. New replies are no longer allowed.