Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Swift Class in Objective C Header

I have been mixing Swift and Objective C just fine but I'm having issues gaining access to a Swift class from the HEADER file of Objective C. I can do so successfully in the .m file.

Within the .h file I import the Xcode generated file that has the format "Appname-Swift.h". However, in doing so I get the message that the file is not found. I can do this same import in my .m file with no issue. However, I need it in the .h file as I reference a Swift class that I need access to with public API.

How can I make use of the Swift class from the .h portion of Objective C?

Example:

#import <UIKit/UIKit.h>
#import "MyApp-Swift.h"

@interface SelectedContactsVC : UIViewController

@property (nonatomic,strong) MapVC *mapVC;

@end

MapVC above is a Swift class.

like image 397
C6Silver Avatar asked Dec 11 '22 16:12

C6Silver


1 Answers

Move #import "MyApp-Swift.h" to .m file.

And make your .h file as:

#import <UIKit/UIKit.h>
@class MapVC;

@interface SelectedContactsVC : UIViewController

@property (nonatomic,strong) MapVC *mapVC;

@end

Swift cannot generate "MyApp-Swift.h", if it's imported from Objective-C header, sort of mutual dependency thing maybe.

like image 154
OOPer Avatar answered Jan 04 '23 20:01

OOPer