画像をファイルに保存できるコードです。
Xcode 11.6 で動作確認済み
strUrl は自分の mac の適切なパスに置き換えてください
import Cocoa func makePNGFromView(view: NSView) { let rep = view.bitmapImageRepForCachingDisplay(in: view.bounds)! view.cacheDisplay(in: view.bounds, to: rep) if let data = rep.representation(using: NSBitmapImageRep.FileType.png, properties: [:]) { let strUrl = "/Volumes/data/home_catalina4/Downloads/akaa.jpg" let urlPath = URL(fileURLWithPath: strUrl) do { try data.write(to: urlPath) } catch { print("Unexpected error: \(error).") } } }