简体   繁体   English

Xcode 10 Swift构建错误:“将非转义的值转换为'T'可能会使其逸出”

[英]Xcode 10 Swift build error: “Converting non-escaping value to 'T' may allow it to escape”

I'm using the Swift-VectorBoolean library, which is currently on Swift 3.2, not yet updated for Swift 4.2, but should still work on Xcode 10. Running this on Xcode 9, it works fine. 我正在使用Swift-VectorBoolean库,该库当前在Swift 3.2上,尚未针对Swift 4.2进行更新,但仍应在Xcode 10上运行。在Xcode 9上运行该库可以正常工作。 On Xcode 10, it gives an error that I'm not sure how to fix. 在Xcode 10上,它给出了一个我不确定如何解决的错误。 This is the function in question: 这是有问题的功能:

typealias MyPathApplier = @convention(block) (UnsafePointer<CGPathElement>) -> Void
// Note: You must declare MyPathApplier as @convention(block), because
// if you don't, you get "fatal error: can't unsafeBitCast between
// types of different sizes" at runtime, on Mac OS X at least.

private func myPathApply(_ path: CGPath!, block: MyPathApplier) {
  let callback: @convention(c) (UnsafeMutableRawPointer, UnsafePointer<CGPathElement>) -> Void = { (info, element) in
    let block = unsafeBitCast(info, to: MyPathApplier.self)
    block(element)
  }

  path.apply(info: unsafeBitCast(block, to: UnsafeMutableRawPointer.self), function: unsafeBitCast(callback, to: CGPathApplierFunction.self))
}

The error is on that last line, path.apply , highlighting the first unsafeBitCast : 错误在最后一行path.apply ,突出显示了第一个unsafeBitCast

Converting non-escaping value to 'T' may allow it to escape

I'm not sure how to modify this code to remove the error, or if this is an issue with Xcode 10. It should be able to compile Xcode 3.2 code.. even updating the code base to Swift 4 in Xcode 9, it still has the same issue. 我不确定如何修改此代码以消除错误,或者这是否是Xcode 10的问题。它应该能够编译Xcode 3.2代码。甚至将代码库更新为Xcode 9中的Swift 4,它仍然有同样的问题。

EDIT: Changing this with the answer from @Vyacheslav allows it to compile, but it gets a runtime error: "Fatal error: Can't unsafeBitCast between types of different sizes" 编辑:使用@Vyacheslav的答案更改它,使其可以编译,但是会遇到运行时错误:“致命错误:不同大小类型之间不能unsafeBitCast”

There is a comment provided above the function which I didn't include in the sample above: 在上面的示例中未包含的功能上方提供了注释:

// Note: You must declare MyPathApplier as @convention(block), because
// if you don't, you get "fatal error: can't unsafeBitCast between
// types of different sizes" at runtime, on Mac OS X at least.

I still don't understand what needs to change here to ensure it builds, and we also don't get a runtime error. 我仍然不明白需要在此处进行哪些更改以确保其构建,并且我们也没有遇到运行时错误。

Use 使用

private func myPathApply(_ path: CGPath!, 
    block: @escaping @convention(block) (UnsafePointer<CGPathElement>) -> Void) {

}

@noescape is now by default @noescape现在默认为

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift 3:关闭使用非转义参数可能允许它逃脱 - Swift 3 :Closure use of non-escaping parameter may allow it to escape 转义闭包捕获非转义参数“函数”Xcode 说 - Escaping closure captures non-escaping parameter 'function' Xcode says 转义闭包捕获非转义参数“完成”(Swift 5) - Escaping closure captures non-escaping parameter 'completion' (Swift 5) Swift:转义闭包捕获非转义参数“onCompletion” - Swift: Escaping closure captures non-escaping parameter 'onCompletion' 错误:将非转义参数&#39;publicationQuery&#39;分配给@escaping闭包 - Error: Assigning non-escaping parameter 'publicationQuery' to an @escaping closure 您可以异步分派非转义的闭包函数吗? - Can you dispatch a non-escaping closure function asynchronously? 在Xcode 8.3.2中的UI测试用例中,转换为当前快速语法“无法调用非函数类型&#39;XCUIElement&#39;的值”时出错 - Getting error while converting to current swift syntax “Cannot call value of non-function type 'XCUIElement'” in UI test cases in Xcode 8.3.2 Swift错误-不变值&#39;&#39;可能无法传入inout - Swift error - immutable value '' may not be passed inout Xcode 10 beta 6错误:访问构建数据库 - Xcode 10 beta 6 error: accessing build database Xcode 10上的FacebookCore Swift编译错误 - FacebookCore Swift Compiler Error on Xcode 10
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM