I'm trying to model my data.
I have a class that contains an optional property of type ExcerciseContent.
import RealmSwift
class Excercise: Object {
var content: ExcerciseContent?
}
The idea is that an Excercise contains content, a duration, and one of two: an Audio or Text.
protocol ExcerciseContent {
var duration: Int { get }
}
protocol AudioExcerciseContent: ExcerciseContent {
var audio: String { get }
}
protocol TextExcerciseContent: ExcerciseContent {
var text: String { get }
}
I found a similar question, however I would like to know if this still applies, and what the response means by "Realm needs to know what the concrete object type that will be linked to is at initialization time."
I've declared the protocol, shouldn't Realm know the object type? Or is it that the object type could be different every time, and so that's why it can't be done?
Realm needs to know what the concrete object type that will be linked to is at initialization time..
Your content
property should either be an another Realm Object or one of the supported property types.