Last active
October 17, 2019 04:42
-
-
Save alimir1/de8f84a747f141dacfc8a4c2b1415e73 to your computer and use it in GitHub Desktop.
This file contains 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 | |
class Animal: NSCopying { | |
var name: String | |
init(name: String) { | |
self.name = name | |
} | |
func copy(with zone: NSZone? = nil) -> Any { | |
return Animal(name: name) | |
} | |
} | |
let animal = Animal(name: "Zebra") | |
let animalCopy = animal.copy() as! Animal | |
animal.name = "Lion" | |
print(animal.name) // Lion | |
print(animalCopy.name) // Zebra |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment