Last active
April 10, 2018 14:31
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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