Skip to content

Update for Swift 4.2 #18

@AndrewHartAR

Description

@AndrewHartAR

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions