mixing objective-c and swift when subclassing

前端 未结 3 1617
感动是毒
感动是毒 2021-02-02 05:47

I\'ve got a subclass of UIViewController written in Swift called \'BaseViewController\'. I now have an \'old\' view controller called \'ViewController1\' written in Objective-C

相关标签:
3条回答
  • 2021-02-02 05:50

    You cannot subclass a Swift class in Objective-C.

    Excerpt from Using Swift with Cocoa and Objective-C

    0 讨论(0)
  • 2021-02-02 06:04

    You cannot subclass a Swift class in Objective-C. cf. towards the end of this section of the docs:

    However, note that you cannot subclass a Swift class in Objective-C.

    0 讨论(0)
  • 2021-02-02 06:10

    It's an compiling error, so U can not subclass a swift class in objc.

    SWIFT_CLASS("_TtC6Swifty14ViewController")
    @interface ViewController : UIViewController
    @end
    
    
    # if defined(__has_attribute) && __has_attribute(objc_subclassing_restricted)
    #  define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA
    #  define SWIFT_CLASS_NAMED(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
    # else
    #  define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
    #  define SWIFT_CLASS_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
    # endif
    #endif
    
    0 讨论(0)
提交回复
热议问题