【发布时间】:2015-10-26 22:23:09
【问题描述】:
我正在尝试在 Objective-C 代码中使用 swift 类。
ThisClass *thisClass = [[ThisClass alloc] init];
但是,在尝试分配和初始化该类时,我收到此错误:
“ThisClass”没有可见的@interface 声明选择器“alloc”
在 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
【问题讨论】:
-
谢谢,我改了 - 试图让真正的源代码保密
-
有道理,但我在顶部有这个:#import "ProjectName-swift.h"
-
成功了。看我的回答。
标签: swift