After reading this tutorial I need some assistance in understanding what the most efficient way to do the following.
When my app is opened, it needs to load a Profile object. Since there should only be one of these in the lifetime of the app I set it up to be a singleton.
Realm seemed to be a great way to save and retrieve data. Upon further viewing it seems I need to have a data model in order to use Realms. After a failed attempt of integrating Object into the Profile.swift shown below I need some assistance in how I should handle this issue. Should I make a second class ProfileDataModel that can be called by Profile to retrieve and save changes, or is there a way to include a Realm Object into a Singleton class?
Profile.swift
class Profile {
//MARK: Singleton
static let sharedInstance = Profile()
//MARK: Properties
var characterName: String
var level: Int
//MARK: Init
private init() {
//TODO: Load from realms
self.characterName = "John Appleseed"
self.level = 50
}
//MARK: Helper Methods
static func save(){
//TODO: Save to Realm
}
}