-
-
Save geosava/db9a7255522436ba0523 to your computer and use it in GitHub Desktop.
swift copy
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 Cocoa | |
class Human:NSCopying | |
{ | |
var name = ".." | |
var spouse:Human? | |
func copy() -> AnyObject! { | |
if let asCopying = ((self as AnyObject) as? NSCopying) { | |
return asCopying.copyWithZone(nil) | |
} | |
else { | |
assert(false, "This class doesn't implement NSCopying") | |
return nil | |
} | |
} | |
func copyWithZone(zone: NSZone) -> AnyObject! { | |
let newValue = Human() | |
newValue.name = name | |
newValue.spouse = spouse | |
return newValue | |
} | |
} | |
var h1 = Human() | |
h1.name | |
var h2 = h1.copy() as Human |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment