Razvan Soneriu
Razvan Soneriu

Reputation: 607

iOS (Swift), Realm migration add a new property to store another realm object

I ran into a strange error while trying to update the migration scheme for an existing Realm model.
Specifically, I try to update the model by adding a property which stores another realm object.
However, it doesn't matter how I try (even by trying to delete the former object and replace it with the new one), realm crashes with the following error "The RMOHomebook.general property must be marked as being optional"
Is there any way of doing this? Why do I need to mark the property as optional since it will never be optional.
Many thanks in advance!

Upvotes: 0

Views: 1471

Answers (1)

kishikawa katsumi
kishikawa katsumi

Reputation: 10603

Is RMOHomebook.general property Object subclass type? RealmSwift doesn't support making optional Object type properties. It is the current limitation of Realm underlying storage engine.

to-one relationships must be optional

https://realm.io/docs/swift/latest/#relationships

See also Realm object definitions cheatsheet. https://realm.io/docs/swift/latest/#cheatsheet

Upvotes: 3

Related Questions