Require the associated type to be present in the @convention block (c)

I want to have a generic way to do something like Swift 3:

public protocol Callable {
    associatedtype In : CVarArg
    associatedtype Out : CVarArg
}

public struct IntCallable : Callable {
    public typealias In = Int
    public typealias Out = Double

    public typealias FunctionalBlock = @convention(c) (In) -> Out

    public func call(_ block: FunctionalBlock) { /* do stuff */ }
}

      

So I would like it to look like this:

public protocol Callable {
    associatedtype In : CVarArg
    associatedtype Out : CVarArg
    typealias FunctionalBlock = @convention(c) (In) -> Out
}

public struct IntCallable : Callable {
    public typealias In = Int
    public typealias Out = Double
}

public extension Callable {
    public func call(_ block: FunctionalBlock) { /* do stuff */ }
}

      

However, I am getting the error:

'(Self.In) -> Self.Out' is not representable in Objective-C, so it cannot be used with '@convention(c)'

      

Is there any limitation I can put on In / Out link types that will allow me to declare a generic FunctionalBlock form? It works fine without @convention(c)

, but I need it to form a C function call.

+3


source to share





All Articles