Skip to content

Instantly share code, notes, and snippets.

@alimir1
Last active October 17, 2019 04:42
Show Gist options
  • Save alimir1/de8f84a747f141dacfc8a4c2b1415e73 to your computer and use it in GitHub Desktop.
Save alimir1/de8f84a747f141dacfc8a4c2b1415e73 to your computer and use it in GitHub Desktop.
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