swiftmultiplatform

Why can't I do this using swift conditionally compiling?


Compiler will show mistakes when I do this:

#if os(iOS)
class AView: UIView {
#else
class AView: NSView {
#endif
    
}

Why can't I do this?

Does it have any methods to do this thing?


Solution

  • Use conditional compiling with a typealias instead:

    #if os(iOS)
    typealias ParentView = UIView
    #else
    typealias ParentView = NSView
    #endif
    
    class AView: ParentView {}
    

    Then you'll be able to extend that type alias.

    Playground