Beginning Metal - Part 2: Getting Started | Ray Wenderlich

In this video tutorial, you'll get started learning about GPU parallel processing and about the Metal pipeline.

This is a companion discussion topic for the original entry at

Nice series! Just a quick nitpick:
At ~9:20, you mention that the command buffer is presented, but this is inaccurate. The command buffer actually schedules a (future) event that presents the MTKView’s drawable after your frame has been rendered into its texture (i.e. render target).

1 Like

Thank you very much for the correction.

I just copied your provided in the video.
import UIKit
import MetalKit

enum Colors {
static let wenderlichGreen = MTLClearColor (red: 0.0, green: 0.4,
blue: 0.21,
alpha: 1.0)}
class ViewController: UIViewController {

var metalView : MTKView{
    return view as! MTKView

var device: MTLDevice!
var commandQueue: MTLCommandQueue!
override func viewDidLoad() {
    // Do any additional setup after loading the view, typically from a nib.
    metalView.device = MTLCreateSystemDefaultDevice()
    device = metalView.device;
    metalView.clearColor = Colors.wenderlichGreen
    commandQueue = device.makeCommandQueue()
    let comandBuffer = commandQueue.makeCommandBuffer()
    let commandEncoder = comandBuffer.makeRenderCommandEncoder(descriptor: metalView.currentRenderPassDescriptor!)



Name of the application is BreakOut.

2017-02-16 18:45:01.841239 Breakout[257:12357] [DYMTLInitPlatform] platform initialization successful
2017-02-16 18:45:01.913739 Breakout[257:12320] Unknown class MKView in Interface Builder file.
Could not cast value of type ‘UIView’ (0x1ae7b8ed8) to ‘MTKView’ (0x1adbfa1d0).
2017-02-16 18:45:01.916116 Breakout[257:12320] Could not cast value of type ‘UIView’ (0x1ae7b8ed8) to ‘MTKView’ (0x1adbfa1d0).

It complies with no problem, but it is Run Time error.
I looked Inspector and unable to find MTKView’.

Best regards

@agha - it looks like you haven’t made the view a MTKView in Interface Builder?

The property metalView expects the view controller’s view to be a MTKView, so you’ll need to go into Main.storyboard and select the view and change the view’s class in the Identity inspector.

1 Like