Mixing objective-c and quick on subclassing

I have a subclass of UIViewController written in Swift called BaseViewController. I now have an "old" view controller called "ViewController1" written in Objective-C, which I want to inherit from "BaseViewController". Following other tips, I imported the Project-Swift.h header file.

My problem arises when subclasses like this

#import <UIKit/UIKit.h> #import "MyProject-Swift.h" @interface ViewController1 : BaseViewController @end 

Mistake:

Cannot subclass a class with the objc_subclassing-limited attribute

and it appears on the @interface line ...

+42
ios objective-c swift
Jun 13 '14 at 11:26
source share
3 answers
+77
Jun 13 '14 at 11:30
source share

You cannot subclass the Swift class in Objective-C. cf. at the end of this section of the documentation :

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

+9
Jun 13 '14 at 11:30
source share

This is a compilation error, so U cannot subclass the 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
Jul 13 '16 at 6:48
source share



All Articles