Skip to content

Instantly share code, notes, and snippets.

@smic
Created October 20, 2016 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smic/5d45dcaf77b902110d74eaeb2e54dcc8 to your computer and use it in GitHub Desktop.
Save smic/5d45dcaf77b902110d74eaeb2e54dcc8 to your computer and use it in GitHub Desktop.
Mysterious Bad Access
import Cocoa
public func with<T>(_ item: T, update: (inout T) throws -> Void) rethrows -> T {
var this = item; try update(&this); return this
}
let path = with(CGMutablePath()) { // <--- Bad Access
$0.move(to: CGPoint(x: 0, y: 0))
$0.addLine(to: CGPoint(x: 100, y: 100))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment