I have some Realm Objects that implement Object and Codable protocols. I would like to store them in a struct container that looks like the following:
struct LocalResource<T> where T: Object & Codable {
init (resource: FileResource) {
self.realmType = T.self
self.resource = resource
}
var codable: [T].Type {
get {
[T].self
}
}
var realmType: T.Type
var resource: FileResource
}
Where I have a generic struct that holds the Realm Model that implements Object and Codable as well as some meta data associated with it. However, when I try to use this struct, such as in the following use:
let localModels: Array<LocalResource<Object & Codable>> = []
I get the error:
'LocalResource' requires that 'Object & Codable' (aka 'RealmSwiftObject & Decodable & Encodable') inherit from 'RealmSwiftObject'
I'm confused because 'Object & Codable' does inherit from RealmSwiftObject. What am I doing wrong?