I have written this to either pull my icons from my own resources in my project or pull them from SF Symbols in SwiftUI. Unfortunately, I get No such module 'UIKit'. I've also tried to import UIKit.UIImage. Has this functionality been deprecated or has it picked up and moved elsewhere? Or am I just doing this wrong?
import SwiftUI
import UIKit
struct GetImage: View {
let name: String
init(_ name: String) {
self.name = name
}
var body: some View {
if let image = UIImage(named: name) {
return Image( uiImage: image )
} else {
return Image( systemName: name )
}
}
}
Edit-2 - works but doesn't allow modifiers
import SwiftUI
struct MyImage: View {
let image: String
init(_ image: String) {
self.image = image
}
var body: some View {
if ( NSImage(named: image) != nil ) {
print( " ---> a" )
return Image( image )
} else {
print( " ---> b" )
return Image( systemName: image )
}
}
}