JsW
JsW

Reputation: 1758

How to invoke a Swift class in a Objective-C file imported in a Swift project?

It's not a dup of this question
I imported Objective-C files into a Swift project. But there is a login controller that has a callback invoking AppDelegate.
But the AppDelegate is a Swift file. According to the Apple's guideline, I added an ExampleProject-Swift.h header file then imported this header file in the login controller. But it doesn't seem to be the right way.

And in the AppDelegate.swift file

The code below is what I did in the ExampleProject-Swfit.h header.

#ifndef ExampleProject_swift_h
#define ExampleProject_swift_h

#import "AppDelegate.swift"
#endif /* ExampleProject_swift_h */

BTW, to use an Objective-C file, I already created an ExampleProject-Bridging-Header.h.
I don't know what's really going on here, anyone has any idea about how to solve this problem?
Thank you for reading my question.

Upvotes: 0

Views: 82

Answers (1)

Dave Weston
Dave Weston

Reputation: 6635

The ExampleProject_Swift.h file is autogenerated by the compiler, so you shouldn't be adding your own.

Also, in the header file you created, you imported a Swift source file as if it was an Objective C header file, and the compiler isn't going to understand that. That is why you're getting all of those strange errors in the LoginViewController implementation file.

Upvotes: 1

Related Questions