Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)
    }
}
like image 443
darrinm Avatar asked Jun 03 '14 07:06

darrinm


2 Answers

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)
    }
}
like image 200
Waruna Avatar answered Oct 04 '22 19:10

Waruna


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

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

like image 43
darrinm Avatar answered Oct 04 '22 20:10

darrinm