swift 2 - Receiver "Some_Swift_Class" for class message is a forward declaration

I'm using xcode 7 and swift to write swift code and objective-c together. I I encounted Receiver "Swift_Class" for class message is a forward declaration


SwiftCode.swift source file

----------------------------------------

class SwiftCode: NSObject {

func someFunction() {

}

}


Objective-CCode.m source file

----------------------------------------

..

SwiftCode *someSwiftCode = [ [SwiftCode alloc] init] <- failed here


Does someone can help me, thanks in advance

Those are the docs to read, but to make Swift code work within objC, it's the automatically generated Swift header he needs to import into the obj-c. It doesn't show up in the project anywhere, but Xcode creates it automatically.


The name of that header will be the name of the product module (usually the project name) followed by -Swift.h


So if your product module is MyApp, the import would be

#import "MyApp-Swift.h"

Accepted Answer

@LCS


You are right and safe my time.

But I still have a little bit question about #import action.

If I declare #import statement at header file that I get error.

If I declare it at implementation file(source.m file) everything is very well.

Why?


thanks for replying

The error you get when the generated Swift header is added to an objC header might be because the objC header is imported to the bridging header for your project which then gets imported into Swift?


You can use the @class directive in your objC header so that you don't need to import the Swift header to have the classes you reference in the header declared.

@class Your SwiftClass1 YourSwiftClass2

etc...

swift 2 - Receiver "Some_Swift_Class" for class message is a forward declaration
 
 
Q