Can Swift protocols be defined as dynamic?

I have converted most of my application to Swift . There are a few Objective-C protocols left and some code that should use Swift styles instead of Objective-C styles.

I have compiled my application using Typhoon . Now, after converting one of the protocols to Swift, I noticed that the intializer is no longer dynamic (DI library required). So I tried to clearly define it dynamically, but got the following error:

Protocol can't be dynamic

He complains that the third argument (my Swift protocol) can never participate as part of Objective-C. It looks like this would be a widespread limitation for Swift / ObjC compatibility. Is the only solution to define a protocol in ObjC and do the Swift classes have this?

The following solution failed:

public protocol WeatherReportDao : NSObjectProtocol { //Extend NSObjectProtocol 
}

      

+3


source to share


1 answer


It seems like the best is to use the @objc directive for the Swift protocol. Example:

@objc public protocol CityDao {

//etc. . . 

}

      



., this is archaic for me as I would really like to report that the protocol requires a dyanmic dispatcher - something that might go beyond Swift-ObjC compatibility.

However, everything works fine.

+5


source







All Articles