0

I have an app that displays a ViewController at some point, which includes a GLKView. All defined within a storyboard. It works just fine, that is, unless you run the app from the phone itself, not launched from within Xcode. Upon presentation of the ViewController and therefore the GLKView, the app instantly crashes.

It doesn't matter if the Installed checkbox is ticked or unticked for the GLKView. Only when I delete it from the storyboard altogether, it won't crash.

Any ideas?

Eric
  • 117
  • 7

1 Answers1

3

I don't know why these things happen but I would consider them a bug. A similar situation happens when adding a WKWebView directly from storyboard. For both the solution is pretty simple: All you need to do is import the module for it. So in your case in your view controller add:

import GLKit

It seems otherwise the framework is not loaded or something.

With ObjectiveC the problem seems to go a level deeper. It seems that the module must manually be imported. Go to your project settings. Select your target. Select "General". Scroll down to bottom and find "Linked Frameworks and Libraries". Below it find a "+" button and search for "GLKit.framework" and add it. This should fix the issue.

enter image description here

Matic Oblak
  • 16,318
  • 3
  • 24
  • 43
  • The `ViewController` already had `GLKit` imported. `#import ` – Eric Jul 24 '19 at 11:36
  • @Eric My apologies, I have missed the Objective-C flag. Please see my edit. I added a solution for ObjectiveC as well. – Matic Oblak Jul 24 '19 at 11:41
  • I just solved it myself too, turns out the Console from macOS works quite well to log errors, and the error pointed out GLKView was unknown, so importing the framework makes sense. – Eric Jul 24 '19 at 11:56
  • Any chance you know why 1) You wouldn't need to import the framework in a Swift project and 2) the app would run in Xcode even without the framework imported? Thanks for your help! – Eric Jul 24 '19 at 11:56
  • 1
    @Eric I don't know but if I had to guess: 1) Swift has different system of implicitly importing frameworks (On older system this didn't exist anyway. You had to always manually add them) which seems to scan the imports from your source files. 2) When attached to debugger a lot of magic happens. Most likely a huge amount of frameworks are preloaded for you in that case. Still I agree this looks very strange. – Matic Oblak Jul 24 '19 at 11:59