2015-10-26 45 views
0

我試圖在Objective-C代碼中使用Swift類。Object-C中的Swift代碼:'ClassName'中沒有可見的@interface聲明選擇器'alloc'

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

然而,試圖分配和初始化類時,我得到這個錯誤:

No visible @interface for 'ThisClass' declares the selector 'alloc'

類被聲明爲這樣的斯威夫特文件:

@objc class ThisClass : NSObject { 

類繼承來自NSObject,所以我不知道它的問題是什麼。

這裏是我的我的項目名 - 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 
+0

謝謝,我改變了它 - 試圖保持真正的源代碼私人 – etayluz

+0

這是有道理的,但我有這個在頂部:#import「ProjectName-swift.h」 – etayluz

+0

讓我們[在聊天繼續討論]( http://chat.stackoverflow.com/rooms/93426/discussion-between-etayluz-and-matt)。 – etayluz

回答

2

的問題是,在你的真正代碼(而不是你是顯示什麼這裏)你有大寫的名字你的變量PresentationData。但這已經是這個班的名字了。這種事情驅使編譯器堅果(並且不適合你的代碼的讀者 - 變量名應該總是以小寫字母開頭)。

+0

這是世界上最愚蠢的事!非常感謝你:)你是一個天才,馬特! – etayluz

+0

我知道你會喜歡它! :) – matt