Reputation: 350
I am learning how to use Realm db, as per examples I'm using the following tasks list with 2 classes: Category and Item, and each category may have many items but each item belong to one category as follows:
Category class
import Foundation
import RealmSwift
final class Category: Object {
@objc dynamic var name : String = ""
let items = List<Item>()
}
Item class
import Foundation
import RealmSwift
final class Item: Object {
@objc dynamic var title: String = ""
@objc dynamic var done : Bool = false
let parentCategory = LinkingObjects(fromType: Category.self, property: "Items")
}
when I run the project, it crashes with the following error:
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=1 "Schema validation failed due to the following errors:
General info:
Xcode version: 11.6
Realm version: 5.4.0
OS version: Catalina 10.15.3
iOS version : 13
I tried cleaning the project, restarting Xcode and Mac itself deleting realm file itself with no luck.
I searched stackoverflow questions, many tutorials and above all Realm's documentation , this code should run fine.
Upvotes: 1
Views: 440
Reputation: 35667
You've just got a typo in the inverse relationship let parentCategory
property. "Items" should be "items" to match the property in the Category
class
final class Item: Object {
@objc dynamic var title: String = ""
@objc dynamic var done : Bool = false
let parentCategory = LinkingObjects(fromType: Category.self, property: "items")
}
Upvotes: 2