Last active
June 10, 2018 12:43
-
-
Save pgpt10/eb0b9dd200716c11ac23568dee08d579 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
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