Skip to content

Instantly share code, notes, and snippets.

@pgpt10 pgpt10/DeepShallow5.swift
Last active Jun 10, 2018

What would you like to do?
class Address: Codable
var city: String?
init(_ city: String?)
{ = 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
You can’t perform that action at this time.