Hi, I am making an iOS video game and want to save the player's data. Is it possible to save an instance of this class into UserDefaults? The class in question has properties that reference other custom classes. This is my class definition:
class Warrior: CombatEligible {
var name: String = ""
var gender: String = ""
var level: Int = 1
var xp: Int = 0
var current_dimension: VirtualDimension = Master_Nexus
var gold: Int = 0
var weapons: [String] = []
var completed_dimensions: [VirtualDimension] = []
var hp: Int = 10
var items: [Item] = []
var knocked_out: Bool = false
var pet: Monster = myPet
var warrior_created = false
var defeated_monsters: Int = 0
var currentTarget: Monster = no_monster
var maxWeight: Int = 0
var defeated_bosses: Int = 0
var inCombat: Bool = checkCombat()
var targetIsInvisible: Bool = false
var inBossBattle: MultipleValues = [false, no_boss]
var invisible: Bool = false
var hypnotized: Bool = false
var switchingEnabled: Bool = true
var switchedToPet: Bool = false
var stunned: Bool = false
var errodable_target_weakened: Bool = false
var errodable_target_weakened_target: Monster = no_monster
var currentWeapon: Weapon?
}
The class has properties that are instances of other classes for example: var pet: Monster = myPet (myPet is an instance of the Monster class). Therefore, Warrior cannot conform to the Codable protocol and cannot be saved to UserDefaults. What do I do?