Importing a Swift protocol in Objective-C class

Jean Lebrument :

I try to import a Swift Protocol named AnalyticProtocol into an Objective-C class named AnalyticFactory.

protocol AnalyticProtocol
{

}

I'm starting from an existing Objective-C project (I didn't create a new Swift project with xCode and I didn't found how configure my Objective-C project to be a Swift project in xCode 6).

In my Swift file I included the .h file named MyProjectName-Swift.h but the compiler return me an error telling me that it doesn't exist. So, I created a .h file named MyProjectName-Swift.h which is actually empty (I don't know what I should put inside).

In the Apple documentation they said that I have to include my .h file named MyProjectName-Swift.h in my .m file. But I need to include it not into my .mfile but into my .h. Does this can be problematic?

When I try to compile I've got this error: :0: error: xxxAnalyticFactory.h:39: cannot find protocol declaration for 'AnalyticProtocol'

And the incriminated code:

@interface AnalyticFactory : NSObject
{
    Class<AnalyticProtocol> _analyticProtocolClass; // The type of the analytic class currently used.
}

I think I don't understand well how can I import a Swift protocol into an Objective-C class.

Does anyone see an error in what I'm doing?

Jamie Forrest :

You need to add the @objc attribute to your Swift protocol like so:

@objc protocol AnalyticProtocol {

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Importing Project-Swift.h into a Objective-C class...file not found

importing swift framework into a objective-c project

Delegating Objective-C Protocol on Swift

swift, objective-c protocol implementation

Swift protocol in Objective-C class

Using a Swift protocol in Objective-C

Implement Objective c protocol in Swift

Make swift class conform to objective c protocol that defines properties

How to create class methods that conform to a protocol shared between Swift and Objective-C?

How can I make my Objective-C class conform to Swift's `Equatable` protocol?

Implementing Objective-C protocol in Swift class

Matching a Swift protocol from an Objective-C Protocol instance

Implement protocol partially in Objective C and partially in Swift

Swift class doesn't conform to objective c protocol inherited from swift protocol

Importing a Swift class that implements a protocol into Objective-C class

A weak property in Objective-C class implementing a Swift protocol

Create object of Objective-C class at runtime in Swift, which conforms to Objective-C protocol

Passing a Swift protocol to an Objective-C pointer

How to make Swift class conform to Objective-C protocol, without exposing it to Objective-C?

Passing dictionary objects to Objective C protocol in Swift

Swift class does not conform to Objective-C protocol with error handling

Objective-C protocol method invisible in Swift

Objective-C protocol not being recognized in Swift

Is it a possible for an objective-c class to implement a swift protocol in the .h

Swift protocol isn't triggering Objective C protocol method

Importing Objective-c framework in Swift?

Implementing an Objective-C protocol in Swift

iOS11 Swift 4 - how to check if Swift class conforms to protocol defined in Objective-C?

How to implement objective C protocol in swift class?