Swift equivalent for @protocol(DelegateType)

ios, objective-c, swift, xcode

Solution

Did you use `@objc` when you declared your protocol?

I believe `SomeProtocol.self` is right right way to pass it but since you're passing it into an obj-c API it needs to be prefixed with `@objc` like this example from the docs:

@objc protocol HasArea {
    var area: Double { get }
}

Edit: Turns out the protocol in question is from a library (written in objective-c, so already compatible with objective-c), not defined in Swift.

That being the case, it's probably a compiler bug, so before you do anything else make sure you're using the latest version of Xcode (beta 3 at the time of writing).

If that doesn't work out, I think Tommy's idea to use `NSProtocolFromString` is the best recourse until the compiler bug is fixed.

Problem

I'm working with ReactiveCocoa in Swift. I need to use the following method: `rac_signalForSelector(selector: Selector, fromProtocol: Protocol?)` Passing the selector works fine with `Selector("method:")`, but I cannot find how to pass the delegate protocol to the `fromProtocol` parameter. What is the proper way to pass the Protocol type from a delegate to a method signature like this? EDIT: Adding method documentation and best attempt The documentation for this method is as follows: selector - The selector for whose invocations are to be observed. If it doesn’t exist, it will be implemented using information from protocol, and may accept non-object arguments and return a value. This cannot have C arrays or unions as arguments or return type. protocol - The protocol in which selector is declared. This will be used for type information if the selector is not already implemented on the receiver. This must not be NULL, and selector must exist in this protocol. I have tried sending in `DelegateType.self`, and I end up receiving this error: Could not find an overload for `rac_signalForSelector` that accepts the supplied arguments

Original source