I already wrote about PaintCode in this post. I think this is one of the most usefull tool, if you want to convert complex vector graphics to Swift of ObjC code.

This time I will show you how to use PaintCode without Storyboard. I will add the Figma file and PaintCode file to GitHub repository. The code itself is very simple.

Step 1. Create a new macOS app in Xcode.

Step 2. Open the PaintCode file and set the following:

Step 3. Export the drawing code from PaintCode and add it to your Xcode project.

Step 4. Add a new NSView class.

Step 5. The following code will draw for us:

import Cocoa

class GaugeView: NSView {

    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)

        // We can use the dirtyRect, which we will define during the initialization of the NSView.
        GaugeCode.drawTemperature(frame: dirtyRect, resizing: .aspectFit)
    }
    
}

Step 6. Add our new custom NSView to the ViewController.

import Cocoa

class ViewController: NSViewController {
    
    let gaugeView: GaugeView = {
        let view = GaugeView(frame: NSRect(x: 0, y: 0, width: 400, height: 400))
        return view
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(gaugeView)
        NSLayoutConstraint.activate([
            gaugeView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            gaugeView.centerYAnchor.constraint(equalTo: view.centerYAnchor)
        ])
    }
}

As I promised it was very simple even without using Storyboard.

You can find the source code here.