1

I have an objective-c class

@interface LightweightGenericHolder<T: NSObject*> : NSObject

@property (nonatomic, strong, readwrite) T value;

@end

I created swift subclass from it

public class LightweightGenericHolderSubclass: LightweightGenericHolder<NSString> {

}

Usage of LightweightGenericHolderSubclass in objective-c code produces an error Use of undeclared identifier 'LightweightGenericHolderSubclass'

How can i make this class visible?

Thanks.

minroff
  • 21
  • 1
  • 4
  • At a minimum, to be visible to ObjC, you need to add `@objc` to the class definition. (I haven't double-checked whether this will fix the entire problem, but it's required since the removal of objc-inference.) – Rob Napier Feb 23 '19 at 13:46
  • 1
    @RobNapier adding _@objc_ flag produces an error **Generic subclasses of '@objc' classes cannot have an explicit '@objc' because they are not directly visible from Objective-C. Replace '@objc ' with ''** – minroff Feb 23 '19 at 13:58
  • 1
    I would say that's your answer. "Generic subclasses of @objc classes are not directly visible from Objective-C." You can't do this. – Rob Napier Feb 23 '19 at 14:01
  • May be there is some workaround? – minroff Feb 23 '19 at 14:02
  • Sure; make a Swift class that is not a subclass of LightweightGenericHolder, and then write a ObjC subclass of LightweightGenericHolder that calls it. (Or just write the entire subclass in ObjC.) But the Swift type can't make use of any `LightweightGenericHolder` code (since it's not a subclass). There is no workaround that looks like "and then my Swift subclass is visible in ObjC." If there were, the compiler would just do that. – Rob Napier Feb 23 '19 at 14:08
  • Okey, I got it. Thank you! – minroff Feb 23 '19 at 15:03

0 Answers0