当我单击侧栏中的眼睛时,实际上可以预览图像。但是,代码的最后一行没有显示任何内容。
//: A Cocoa based Playground to present user interface
import AppKit
import PlaygroundSupport
let nibFile = NSNib.Name("MyView")
var topLevelObjects : NSArray?
let imgView = NSImageView(frame:NSRect(x: 0, y:0 , width: 300, height: 400))
imgView.image = NSImage(byReferencingFile: "/Users/me/Code/MyPlayground.playground/Resources/image.png")
PlaygroundPage.current.liveView = imgView
最佳答案
打开项目导航器到左侧
选择资源文件夹
右键单击,然后单击“将文件添加到'资源'”
您可以这样使用-> imgView.image = UIImage(named:“ image_name”)
You can see in this image
关于swift - 如何使用NSImage在Xcode Playground中显示图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57989988/