Pleasse help

Ok so this is the error:

-[Game_engine.GameView _setIsContentViewController:]: unrecognized selector sent to instance 0x10180c600
2020-09-16 17:51:49.718223+0200 Game engine [9793:272445] Failed to set (contentViewController) user defined inspected property on (NSWindow): 
-[Game_engine.GameView _setIsContentViewController:]: unrecognized selector sent to instance 0x10180c600

And the code:

import MetalKit

class GameView: MTKView {
    
    // Command Queue (60FPS)
    var commandQueue: MTLCommandQueue!
    var renderPipelineState: MTLRenderPipelineState!
    
    // Initializer
    required init(coder: NSCoder) {
        super.init(coder: coder)
        
        // Default Device
        self.device = MTLCreateSystemDefaultDevice()
        
        // Color called after each frame
        self.clearColor = MTLClearColor(red: 0.43, green: 0.73, blue: 0.35, alpha: 1.0)
        
        // Pixel Format
        self.colorPixelFormat = .bgra8Unorm
        
        // Command queue
        self.commandQueue = device?.makeCommandQueue()
        
        createRenderPipelineState()
    }
    
    func createRenderPipelineState() {
        
        // MTL Library
        let library = device?.makeDefaultLibrary()
        
        // Make VertexFunction and FragmentFunction
        let vertexFunction = library?.makeFunction(name: "vertex_shader")
        let fragmentFunction = library?.makeFunction(name: "fragment_shader")
        
        // Render pipeline descriptor
        let renderPipelineDescriptor = MTLRenderPipelineDescriptor()
        renderPipelineDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm
        renderPipelineDescriptor.vertexFunction = vertexFunction
        renderPipelineDescriptor.fragmentFunction = fragmentFunction
        
        // Render Pipeline State
        do {
            renderPipelineState = try device?.makeRenderPipelineState(descriptor: renderPipelineDescriptor)
        } catch let error as NSError {
            print(error)
        }
    }
    
    // Draw function
    override func draw(_ dirtyRect: NSRect) {
        guard let drawable = self.currentDrawable, let renderPassDescriptor = self.currentRenderPassDescriptor else { return }
        
        // Command Queue Texture Holder
        let commandBuffer = commandQueue.makeCommandBuffer()
        let renderCommandEncoder = commandBuffer?.makeRenderCommandEncoder(descriptor: renderPassDescriptor)
        
        renderCommandEncoder?.setRenderPipelineState(renderPipelineState)
        
        // Send Info to renderCommandEncoder
        renderCommandEncoder?.endEncoding()
        commandBuffer?.present(drawable)
        commandBuffer?.commit()
    }
}

I am using Xcode 12 beta 6.

NSWindow expects to see a UIViewController derived type into its contentViewController property. Your GameView derives from MTKView which I think is a subclass of UIView not UIViewController.

Also, this question is about UIKit and MetalKit, which are Apple's private framework. So I'd suggest that future questions of this nature are asked over https://developer.apple.com/forums/ instead.

Terms of Service

Privacy Policy

Cookie Policy