I copy and paste the code from realm doc. But don't know how to change teh section i commented next to to indicate. (at the bottom) Below is the full error message I get:
error initializing newrealm, Error Domain=io.realm Code=10 "Migration is required due to the following errors: - Property 'Item.dateCreated' has been added." UserInfo={NSLocalizedDescription=Migration is required due to the following errors: - Property 'Item.dateCreated' has been added., Error Code=10} 2018-07-30 21:25:24.231575-0400 Todoey[87561:3063712] *** Terminating app due to uncaught exception 'RLMException', reason: 'Invalid property name 'dateCreated' for class 'Category'.'
Below is the code in witch I attempted the migration:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
print(Realm.Configuration.defaultConfiguration.fileURL)
do {
let realm = try Realm()
} catch {
print("error initializing newrealm, \(error)")
}
//Migration
let config = Realm.Configuration(
schemaVersion: 1,
migrationBlock: { migration, oldSchemaVersion in
if (oldSchemaVersion < 1) {
migration.enumerateObjects(ofType: Category.className()) { (old, new) in
new!["dateCreated"] = Date()
}
migration.enumerateObjects(ofType: Item.className()) { (old, new) in
new!["dateCreated"] = Date()
}
}
})
Realm.Configuration.defaultConfiguration = config
//Migration X
return true
}
It appears that the problem is above where the "// combine name fields into a single field" comment is. I need to change those values to the following:
class Item: Object {
@objc dynamic var title: String = ""
@objc dynamic var done: Bool = false
@objc dynamic var dateCreated = NSDate() //this is the new data
var parentCategory = LinkingObjects(fromType: Category.self, property: "items")
}