Reputation: 3
I added the Object class to the Aps and Alert class and now the application crashes when trying to access the Realm configuration with an error:
Thread 1: Exception: "Invalid class subset list:\n- 'PushNotification.aps' links to class 'Aps', which is missing from the list of classes managed by the Realm"
I tried to raise the schema version, delete completely Derived Data, delete the app - nothing helped.
Realm configuration file
struct RealmGatewayImp: RealmGateway {
let configuration: Realm.Configuration
private init(config: Realm.Configuration) {
configuration = config
}
var realm: Realm {
try! Realm(configuration: configuration)
}
// MARK: - Push notification
// The app crashes here
private static let pushConfig = Realm.Configuration(
fileURL: try! Path.inSharedContainer("pushNotifications.realm"),
schemaVersion: 1,
deleteRealmIfMigrationNeeded: true,
objectTypes: [PushNotification.self])
public static var push: RealmGatewayImp = {
RealmGatewayImp(config: pushConfig)
}()
}
Parent class
@objcMembers
final class PushNotification: Object, Codable {
dynamic var accCodeIso: String?
dynamic var account: String?
dynamic var accType: String?
dynamic var amount: String?
dynamic var aps: Aps?
dynamic var commentary: String?
dynamic var corrAccCodeIso: String?
dynamic var corrAccount: String?
dynamic var corrAccType: String?
dynamic var date: Date?
dynamic var docType: String?
dynamic var id: String?
dynamic var payAmount: String?
override static func primaryKey() -> String? {
"id"
}
}
Class of the parameter
@objcMembers
final class Aps: Object, Codable {
dynamic var alert: Alert?
}
@objcMembers
final class Alert: Object, Codable {
dynamic var body: String?
dynamic var title: String?
}
Upvotes: 0
Views: 600
Reputation: 35667
If you're going to specify which objects Realm is managing, it needs to be a complete list. Instead of
objectTypes: [PushNotification.self])
try
objectTypes: [PushNotification.self, Aps.self, Alert.self])
Upvotes: 1