Import Image from SwiftUI even if project already declares an internal Image type

I have this code in my project

#if os(macOS)
import Cocoa

typealias Image = NSImage
#elseif os(iOS)
import UIKit

typealias Image = UIImage
#endif

Because of this, in a file with import SwiftUI I would have to use SwiftUI.Image to disambiguate. Is it possible to declare that whenever I use Image in that file, it should not use my internal declaration but the SwiftUI type instead?

You could put your typealias into your own class, like this:

#if os(macOS)
import Cocoa
#elseif os(iOS)
import UIKit
#endif

class CrossPlatform {
#if os(macOS)
    typealias Image = NSImage
#elseif os(iOS)
    typealias Image = UIImage
#endif
}

Then you would have:

    var swiftUIImage: Image
    var crossPlatformImage: CrossPlatform.Image

No way. All the declarations in your app project always precede imported declarations. You can move your own declaration of Image into subproject, of course that may force you to rewrite many parts of your project. Generally, declaring too generic names like Image would not be recommended.

Import Image from SwiftUI even if project already declares an internal Image type
 
 
Q