4

So I am slowly adding more swift files to codebase. Suppose I have class in Objective c:

ListData<Type : CSJSONData *> : ServerData <CSListData>

I want to subclass it in swift class like this:

@objc class ArticlesData: ListData<Article> 

Compiler gives me error:

Generic subclasses of '@objc' classes cannot have an explicit '@objc' because they are not directly visible from Objective-C
Replace '@objc ' with ''

But I need to have it @objc to keep available in my objc part of code ! How to do it ?

1 Answer 1

3

From The Swift Programming Language (4.2), Attributes:

The compiler implicitly adds the objc attribute to subclasses of any class defined in Objective-C. However, the subclass must not be generic, and must not inherit from any generic classes. You can explicitly add the objc attribute to a subclass that meets these criteria, to specify its Objective-C name as discussed below.

Unfortunately for you this is pretty definitive.

Sign up to request clarification or add additional context in comments.

1 Comment

My development with swift in shared codebase can be named fighting with swift compiler and looking on build progress line ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.