Skip to content

Instantly share code, notes, and snippets.

@bjhomer
Last active May 19, 2017 13:17
Show Gist options
  • Save bjhomer/3e5f1ebe4b3da14d489f3fe7903abdf0 to your computer and use it in GitHub Desktop.
Save bjhomer/3e5f1ebe4b3da14d489f3fe7903abdf0 to your computer and use it in GitHub Desktop.
import Foundation
enum Foo: Error {
case dogAteHomework
}
func makesAnError(_ error: NSErrorPointer) {
autoreleasepool {
error?.pointee = Foo.dogAteHomework as NSError
}
}
var err: NSError? = nil
makesAnError(&err) // EXC_BAD_ACCESS in objc_retain
print(err)
@bjhomer
Copy link
Author

bjhomer commented May 19, 2017

The best fix I've found so far:

func makesAnError(_ error: NSErrorPointer) {
    var localError: NSError?
    autoreleasepool {
        localError = Foo.dogAteHomework as NSError
    }
    error?.pointee = localError
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment