Shazniq
Shazniq

Reputation: 453

How to display image from known image path - SwiftUI

I've got an array of image URLs (all from storage, not internet). How can I show the images themselves? Simplified code:

@Binding var files:[URL]//Array of image URLs taken from an NSOpenPanel instance

Form{
    if files.count>0{
        Image(files[0].path)//Problem
    }
}

Upvotes: 3

Views: 2211

Answers (1)

jnpdx
jnpdx

Reputation: 52312

You say NSOpenPanel, so I'm making going to make the assumption here that we don't need to worry about waiting to load the image over a network:

if let nsImage = NSImage(contentsOf: url) {
  Image(nsImage: nsImage)
}

Upvotes: 7

Related Questions