In the pre-release documentation there appears to be no Swift version of CGPathApply. Is there an equivalent or alternative? I'm trying to get all subpaths of a CGPath so that I can redraw it from a different starting point.
相关问题
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
- Get the NSRange for the visible text after scroll
- UIPanGestureRecognizer is not working in iOS 13
- What does a Firebase observer actually do?
相关文章
- Using if let syntax in switch statement
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
- How can I vertically align my status bar item text
- Adding TapGestureRecognizer to UILabel in Swift
- Attempt to present UIAlertController on View Contr
- Swift - Snapshotting a view that has not been rend
Swift 3.0
In Swift 3.0, you can use
CGPath.apply
like this:Swift 2.2
With the addition of
@convention(c)
, you can now callCGPathApply
directly from Swift. Here's a wrapper that does the necessary magic:(Note that
@convention(c)
isn't mentioned in my code, but is used in the declaration ofCGPathApply
in the Core Graphics module.)Example usage:
Dmitry Rodionov has produced a function for converting a Swift function to a CFunctionPointer (see https://github.com/rodionovd/SWRoute/wiki/Function-hooking-in-Swift).
I am using this successfully with CGPathApply along with a Swift callback function. (code at http://parker-liddle.org/CGPathApply/CGPathApply.zip) Although as Dmitry says this is a reverse engineered function and not a supported one.
Here's the highlights from Ole Begemann's great post (thanks @Gouldsc!), adapted for Swift 3, which allows for accessing the individual elements composing a
UIBezierPath
instance: