-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
realmcollection notification cause crashed to application #4656
Comments
You say that your application is crashing: what is the nature of the crash? Is an exception being thrown, a segfault occurring, or something else? Can you share the crash log and backtrace of the crash? |
Given that this is crashing in Since collection notifications carry "diff" information, it expects the state of the table view to match up exactly with the state of the collection being observed. |
@bdash Sure I will share the crash log shortly @jpsim I m not updating the data from elsewhere in code but the Actually I am using this function to fetch the data from realm and filter and sort it on basis of criteria func getTasks(sortParameter:String = "",ascendingFlag:Bool = true){
let realm = try! Realm()
tasks = realm.objects(RMCAssignmentObject.self)
tasks = tasks.filter("status = %@",currentStatus.rawValue)
// sortData()
filterData()
assignmentTableView.reloadData()
}
func filterData(){
if Singleton.sharedInstance.assignedByValue != nil {
if Singleton.sharedInstance.assignedByValue?.uppercased() == "SELF" {
tasks = tasks.filter("selfAssignment = %@","true")
}else{
tasks = tasks.filter("selfAssignment = %@","false")
}
}
} This function is called in Normally the code is working fine, but it fails when I have set filter and from API end, new data is added in realm collection, it crashed. Also the code is working fine when i comment this: func updateUI(changes: RealmCollectionChange<Results<RMCAssignmentObject>>) {
guard let tableView = self.assignmentTableView else { return }
/**
switch changes {
case .initial(_):
tableView.reloadData()
case .update(_, let deletions, let insertions, let modifications):
tableView.beginUpdates()
tableView.insertRows(at: insertions.map {IndexPath(row: $0, section: 0)}, with: .automatic)
tableView.deleteRows(at: deletions.map {IndexPath(row: $0, section: 0)}, with: .automatic)
tableView.reloadRows(at: modifications.map({ IndexPath(row: $0, section: 0) }), with: .automatic)
tableView.endUpdates()
case .error(let error):
print(error)
}
**/
tableView.reloadData()
} |
Sorry for the delay. Would you be willing to send over a sample project that we can run to reproduce this bug? Without understanding your code it's difficult to make any progress. You can send a zip file to [email protected]; if you do we'd be happy to continue looking into the problem. |
The fact that you're changing which query is backing the table view without changing which query you're observing for change notifications is almost certainly the culprit here, @Raghvendra7. One way to fix this would be to tear down the previous notification block and re-register: func getTasks(sortParameter:String = "",ascendingFlag:Bool = true){
let realm = try! Realm()
tasks = realm.objects(RMCAssignmentObject.self)
tasks = tasks.filter("status = %@",currentStatus.rawValue)
// sortData()
filterData()
notificationToken.stop()
notificationToken = notificationSubscription(tasks: tasks)
} |
thanks @jpsim |
with reference to issue #4425
Hi i m facing same issue using RealmSwift (2.3.0):
Xcode 8.2.1
I have used realmcollection notification .But got crashed while setting a filter query
Use case is suppose a filter is set on a list and new data is added in realmcollection. A Realm notification is generated which updated the table.But it crashed on tableview endupdate.
notification code are as follows
Pls provide any solution
The text was updated successfully, but these errors were encountered: