When I want to set a image from my disc (/Users/me/Desktop/image.png) to the image of my NSImageView
with NSImage(byReferencingFile: )
it does not show it.
When I try NSImage(named: )
with an image stored in the assets-folder, it works.
The code within the viewController
class ViewController: NSViewController {
@IBOutlet var imageView: NSImageView!
override func viewDidLoad() {
super.viewDidLoad()
imageView.image = NSImage(byReferencingFile: "/Users/me/Desktop/image.png")
}
}
The imageView fills the entire window.
So I want to load the image stored on disk or at a specified URL.
Willeke helped me to find the solution. I had to switch
App Sandbox
in the entitlements-file fromYES
toNO
You can't add image from desktop to UIimageView, you only can add image (dragging) into project folders and then select the name image into UIimageView properties (inspector).
To get to the UserDir you'll have to use:
And from there you can add the path to the Image Here is a tutorial on using the File System https://www.raywenderlich.com/666-filemanager-class-tutorial-for-macos-getting-started-with-the-file-system
Hope this helps.