Код: Выделить всё
@interface Discussion : NSManagedObject
@property (nonatomic, retain) TMMessage *lastMessage;
@end
Код: Выделить всё
@interface TMMessage : NSManagedObject
@property (nonatomic, retain) NSDate * timeStamp;
@end
Код: Выделить всё
let sort = NSSortDescriptor(key: #keyPath(Discussion.lastMessage.timeStamp), ascending: false))
fetchRequest.sortDescriptors = [sort]
Приведенный ниже метод делегата вызывается с типом == .update, не вводите == .move.
Код: Выделить всё
func controller(_ controller: NSFetchedResultsController,
didChange anObject: Any,
at indexPath: IndexPath?,
for type: NSFetchedResultsChangeType,
newIndexPath: IndexPath?) {
switch type {
case .insert:
guard let newIndexPath else { return }
tableView.insertRows(at: [newIndexPath], with: .fade)
case .delete:
guard let indexPath else { return }
tableView.deleteRows(at: [indexPath], with: .fade)
case .move:
guard let indexPath, let newIndexPath else { return }
tableView.moveRow(at: indexPath, to: newIndexPath)
case .update:
guard let indexPath else { return }
tableView.reloadRows(at: [indexPath], with: .automatic)
@unknown default:
break
}
}
Подробнее здесь: https://stackoverflow.com/questions/785 ... leviewcell
Мобильная версия