RLMException attempting to create object with an existing primary key after check
try! self.realm.write {
self.realm.add(newStudent, update: true)
}
You're adding same Object (student) with existing primary key. So you can just update current one. Instead of deleting and adding new one.