Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Swift 4.2 #18

Open
AndrewHartAR opened this issue Jul 29, 2018 · 1 comment
Open

Update for Swift 4.2 #18

AndrewHartAR opened this issue Jul 29, 2018 · 1 comment

Comments

@AndrewHartAR
Copy link

AndrewHartAR commented Jul 29, 2018

The update to Swift 4 is mostly fairly straight forward - only a few changes necessary. However, there's 1 thing that I'm not able to update myself, in CGPathBridge CGPath file:

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))
}

Xcode 10 throws an error on the last line, highlighting unsafeBitCast:
Converting non-escaping value to 'T' may allow it to escape

Even with the Swift version set to 3.2, or updating it to 4.0 and then setting it to 4.0, it still won't let me build with this line existing. Perhaps an Xcode 10 issue, worth understanding.

@endanke
Copy link

endanke commented Nov 26, 2018

The reason and the solution for that can be found here:
https://stackoverflow.com/questions/51579037/xcode-10-swift-build-error-converting-non-escaping-value-to-t-may-allow-it-t/51579294

In short, now by default blocks are non-escaping, so we just have to add the @escaping tag in front of the MyPathApplier type in the function definition:
private func myPathApply(_ path: CGPath!, block: @escaping MyPathApplier)

In this same file, there's also another function called apply, you have to do the same for the parameter in that:
func apply(_ fn: @escaping (PathElement) -> Void)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants