How to use GLKit within the Xcode OS X Swift Playground?

darrinm picture darrinm · Jun 3, 2014 · Viewed 7.2k times · Source

I'm trying to use GLKit within the Xcode 6 OS X Swift Playground but the

import GLKit

doesn't seem enough to make Playground recognize GLKView. Any ideas?

import Cocoa
import GLKit
import OpenGL

let frame = CGRect(x: 0, y: 0, width: 400, height: 300)
class TriangleView: GLKView { // ERROR: Use of undeclared type 'GLKView'
    override func drawRect(dirtyRect: NSRect) {
        glClearColor(0.0, 0.0, 0.1, 1.0)
    }
}

Answer

Waruna picture Waruna · Jun 3, 2014

You can create iOS project and add new .playground file inside that project. Then you can import GLkit, I also had to import OpenGLES instead of OpenGL.

import UIKit

import GLKit
import OpenGLES

let frame = CGRect(x: 0, y: 0, width: 400, height: 300)
class TriangleView: GLKView { // ERROR: Use of undeclared type 'GLKView'
    override func drawRect(dirtyRect: CGRect) {
        glClearColor(0.0, 0.0, 0.1, 1.0)
    }
}