Last active
November 23, 2015 18:39
-
-
Save zwaldowski/4388226c19dc7818e9f0 to your computer and use it in GitHub Desktop.
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 copied() -> Self { | |
| let copied = copyWithZone(nil) | |
| assert(copied is Self, "Invalid downcast while copying instance of \(Self.self), did you mean to use 'as?'") | |
| return unsafeDowncast(copied) | |
| } | |
| } | |
| extension Optional where Wrapped: NSCopying { | |
| func copied() -> Wrapped? { | |
| return map { $0.copied() } | |
| } | |
| } | |
| let object: NSOrderedSet = [ 1, 2, 3, 4 ] | |
| let copy = object.copied() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment