迁移到Swift 2之后,我遇到了一个错误,指出我现在应该使用@convention(c)(T) – >我试过排列,但到目前为止还没有运气.
func foo(context: AnyObject?,width: CGFloat) -> Int { } let bar = unsafeBitCast(foo,CFunctionPointer<(UnsafeMutablePointer<Void>,Float) -> Int>.self)
您不再需要在Swift 2中创建CFunctionPointer.相反,您可以通过调用约定来注释您的类型,在本例中为c,并直接使用它.
原文链接:https://www.f2er.com/swift/320260.htmltypealias CFunction = @convention(c) (UnsafeMutablePointer<Void>,Float) -> Int let bar = unsafeBitCast(foo,CFunction.self)
The Swift Programming Language的Type Attributes部分中@convention描述的相关位是:
The c argument is used to indicate a C function reference. The function value carries no context and uses the C calling convention.