Reputation: 1670
Am getting error while calling swift function in objective c file. I have created "-Swift.h" file.
I have created ".swift" file. My code here is
import Foundation
@objc class className : NSObject {
@objc func someFunc(sender: AnyObject) {
//Some code
}
}
I have created "-Swift.h" header file. My code here is
#ifndef ProjectName_Swift_h
#define ProjectName_Swift_h
#endif /* ProjectName_Swift_h */
@class className;
@interface className : NSObject
-(void)someFunc;
@end
In my objective C ".m" file am calling the swift function.
#import "XXX-Swift.h"
- (void)viewDidLoad
{
[super viewDidLoad];
className *obj = [[className alloc]init];
[obj someFunc];
}
Now am getting error in "XXX-Swift.h" file.
ERROR: Cannot find interface declaration for 'NSObject', super class for 'className'.
Upvotes: 1
Views: 836
Reputation: 1670
I found difference between manually creating -Bridging-header file and automatically Xcode generated -Bridging-header file. I have deleted the -Swift.h file and manually created -Bridging-header file. Added -Bridging-header(Xcode generated one) file. It automatically created -Swift.h file after successful build of project.
Upvotes: -1
Reputation: 6691
delete the file you created ending in -Swift.h
, that file is auto-generated by Xcode.
you can view the Xcode generated version (after a successful build) if you command click #import "XXX-Swift.h"
if you go into your build settings and search for SWIFT_OBJC_INTERFACE_HEADER_NAME
you can see the file name.
Upvotes: 3
Reputation: 272
you have to created Bridging header file and import you swift file there.
Use this link, it will help you
Upvotes: 0