[swift-users] Cannot subclass a class with objc_subclassing_restricted attribute

Joe Groff jgroff at apple.com
Mon Apr 17 10:54:22 CDT 2017


> On Apr 14, 2017, at 7:41 PM, Rick Mann via swift-users <swift-users at swift.org> wrote:
> 
> I'm refactoring some Objective-C code to inherit from a new Swift super class. This has been going okay, and I've been cleaning up build errors as I spot them (some auxiliary enums caused enum name changes, etc.).
> 
> But my last error seems to be that I can't subclass the Swift class: "Cannot subclass a class with objc_subclassing_restricted attribute". I didn't notice it before, and all the online references that say you can't subclass a Swift class point to a Swift document that no longer mentions that. They also don't say what they mean by "Swift" class (e.g. is it not marked with @objc?).
> 
> In any case, my Swift class looks like:
> 
> @objc
> class
> Camera : NSObject
> {
>    ...
> }
> 
> And my ObjC class looks like:
> 
> @interface
> MCPCamera : Camera
> 
>    ...
> 
> @end
> 
> I feel like this is a reasonable thing to try to do. Is it just not possible?

Subclassing Swift classes from Objective-C is not supported. If the documentation no longer mentions that restriction, we should fix that. Where is that document that you're referring to?

-Joe


More information about the swift-users mailing list