Last active
August 19, 2019 06:42
-
-
Save godrm/24ce6b64c3944da2074a020de84a9048 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 Animal : Codable { | |
var type : String { | |
return "animal" | |
} | |
} | |
class Dog : Animal { | |
override var type : String { | |
return "dog" | |
} | |
} | |
class Cat : Animal { | |
override var type : String { | |
return "cat" | |
} | |
} | |
var array : [Animal] = [Dog(), Cat(), Dog(), Cat()]; | |
array.forEach{ print($0.type) } | |
var data = try PropertyListEncoder().encode(array) | |
var restoreArray = try? PropertyListDecoder().decode(Array<Animal>.self, from: data) | |
restoreArray?.forEach{ print($0.type) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment