Skip to content

Instantly share code, notes, and snippets.

@danielctull
Last active April 10, 2018 14:31
Show Gist options
  • Save danielctull/52a22b1ee4fa6a9cfd9f965bac691502 to your computer and use it in GitHub Desktop.
Save danielctull/52a22b1ee4fa6a9cfd9f965bac691502 to your computer and use it in GitHub Desktop.
NSCopying's copy() returns Any by default, which is terribly annoying. Here I force it to be of the same type as Self.
import Foundation
extension NSCopying {
func copy() -> Self {
// Use copy(with zone:) here to disambiguate between this
// overload and the one we actually want to call.
let c = copy(with: nil)
// Copies will be of type self, right??
return c as! Self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment