相关疑难解决方法(0)

要求关联类型在@convention(c)块中可表示

我想有一种通用的方式来做类似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 */ }
}
Run Code Online (Sandbox Code Playgroud)

所以我希望它看起来像这样:

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

public struct IntCallable : Callable {
    public typealias …
Run Code Online (Sandbox Code Playgroud)

swift

6
推荐指数
1
解决办法
155
查看次数

标签 统计

swift ×1