Skip to content

Instantly share code, notes, and snippets.

@pgpt10
Last active June 10, 2018 12:43
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/eb0b9dd200716c11ac23568dee08d579 to your computer and use it in GitHub Desktop.
Save pgpt10/eb0b9dd200716c11ac23568dee08d579 to your computer and use it in GitHub Desktop.
class Address: Codable
{
var city: String?
init(_ city: String?)
{
self.city = city
}
}
var arr1 = [Address("Mumbai"), Address("Bangalore")]
if let data = try? JSONEncoder().encode(arr1) //Serializing arr1
{
var arr2 = try? JSONDecoder().decode([Address].self, from: data) //De-serializing arr1
//This will create a true Deep Copy of arr1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment