Object-C 中的 swift 代码:没有可见的 'ClassName' @interface声明选择器 'alloc'



我想在Objective-C代码中使用一个快速的类。

 ThisClass *thisClass = [[ThisClass alloc] init];

然而,当尝试分配和初始化该类时,我得到这个错误:

没有为'ThisClass'声明选择器'alloc'的可见@interface

在Swift文件中是这样声明的:

@objc class ThisClass : NSObject {

这个类继承自NSObject,所以我不知道它的问题是什么。

这是我的类在我的ProjectName-swift.h:

SWIFT_CLASS("_TtC21ProductName16ClassName")
@interface ThisClass : NSObject
@property (nonatomic, copy) NSArray<Presentation *> * __nonnull presentations;
@property (nonatomic, copy) NSArray<Presentation *> * __nonnull userPresentations;
@property (nonatomic, strong) NSCache * __nonnull imageCache;
- (UIImage * __nullable)imageForPresentationSlideWithPresentation:(Presentation * __nonnull)presentation slideNumber:(NSInteger)slideNumber;
- (UIImage * __nullable)thumbnailForPresentationSlideWithPresentation:(Presentation * __nonnull)presentation slideNumber:(NSInteger)slideNumber;
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end

问题在于,在您的实际代码中(与您在这里显示的相反),您将变量PresentationData的名称大写。但这已经是类名了。这种事情会让编译器抓狂(而且对代码的读者也不好——变量名应该总是以小写字母开头)。

最新更新