【发布时间】:2020-01-23 05:19:41
【问题描述】:
如何将CalendarEvent.notes 更改为可选(可为空)?
class CalendarEvent: Object {
@objc dynamic var date: String = ""
@objc dynamic var notes: String = ""
@objc dynamic var notification: String = ""
}
Realm 数据库已经填充了数据。
我希望在 Realm 数据库中将 notes 属性更改为可为空。
如果我尝试@objc dynamic var notes: String? = "",则会出现运行时错误,说明Migration is required due to the following errors: - Property 'CalendarEvent.notes' has been made optional.
根据 Realm 文档,在迁移期间重命名属性是实现此目的的一种方法。是否可以将此属性更改为可为空且无需重命名?
【问题讨论】:
-
试试这个
@objc dynamic var date: String? -
@Anbu.Karthik 这会导致运行时错误指出
Migration is required due to the following errors: - Property 'CalendarEvent.notes' has been made optional. -
您必须更新架构版本,例如`let configuration = Realm.Configuration(schemaVersion: 2)`
-
我正在尝试执行此stackoverflow.com/a/48899642/10555547 但在 Realm swift 中代替