Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pgpt10
Last active June 10, 2018 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgpt10/0f096ea39e6c3ad4a56463c244c1b775 to your computer and use it in GitHub Desktop.
Save pgpt10/0f096ea39e6c3ad4a56463c244c1b775 to your computer and use it in GitHub Desktop.
class Address: NSObject, NSCopying
{
var city: String?
init(_ city: String?)
{
self.city = city
}
func copy(with zone: NSZone? = nil) -> Any
{
let address = Address(self.city)
return address
}
}
var a1 = Address("Mumbai")
var a2 = a1.copy() as! Address //This will create a Deep Copy of a1
print(a1.city) //Mumbai
print(a2.city) //Mumbai
a2.city = "Bangalore"
print(a1.city) //Mumbai
print(a2.city) //Bangalore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment