5

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)
    }
}
darrinm
  • 9,117
  • 5
  • 34
  • 34

2 Answers2

9

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)
    }
}
Waruna
  • 1,174
  • 1
  • 9
  • 20
  • Thanks but I'm using an OSX Playground which can't import OpenGLES. The iOS Playground doesn't seem to have the XCPlayground facility. – darrinm Jun 03 '14 at 17:45
  • Then as you suggested NSOpenGLView instead of GLKView – Waruna Jun 03 '14 at 18:18
  • @Waruna do you know how to enable live views in xcode ? – Lena Bru Jun 04 '14 at 16:46
  • @LenaBru What you mean by live views? Are you talking about Xcode6 playground? – Waruna Jun 04 '14 at 18:09
  • @Waruna the manual of swift says that i can write custom views, and have them rendered in xcode interface builder, but the xcode keeps complaining that it cant render the views, because the bundle isnt executable – Lena Bru Jun 04 '14 at 18:20
  • @LeanBru I think this should go has a separate question. if possible post a new question with you code. Then we can see whats going wrong. – Waruna Jun 04 '14 at 18:28
  • Just out of interest @Waruna, are you able to access GLKit Math types by importing GLKit? I don't seem to be able to get at them. – Ephemera Jun 05 '14 at 03:09
  • @ephemera looks like, it is. GLKit.GLKMathDegreesToRadians(90) gives me 1.571 – Waruna Jun 08 '14 at 19:35
3

There is no GLKView in OS X! From Apple documentation:

In OS X, NSOpenGLView class subsumes the GLKView and GLKViewController classes in iOS.

darrinm
  • 9,117
  • 5
  • 34
  • 34