这在新的Swift项目中不起作用。在AppDelegate中给我一个EXC_BAD_ACCESS code=1 error
。
UIViewController.swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
view.layoutIfNeeded()
Test(view: view)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Test.swift
import UIKit
import GLKit
import OpenGLES
final class Test: NSObject {
init(view: UIView) {
super.init()
let context = EAGLContext(API: EAGLRenderingAPI.OpenGLES2)
EAGLContext.setCurrentContext(context)
let glView = GLKView(frame: view.bounds)
glView.context = context
glView.delegate = self
view.addSubview(glView)
}
}
extension Test: GLKViewDelegate {
func glkView(view: GLKView, drawInRect rect: CGRect) {
glClearColor(1.0, 0.0, 0.0, 1.0)
glClear(GLbitfield(GL_COLOR_BUFFER_BIT))
}
}
将所有代码放在ViewController
中确实有效。
我正在构建一个更大的应用程序,它具有与此类似的设置。但得到了很多EXC_BREAKPOINT code=1 errors
。如果我在模拟器中运行,则此错误会有所不同。