From ef8c726f17fdc6816f6a5e9db4a4db8dc4652634 Mon Sep 17 00:00:00 2001 From: Anton Schukin Date: Tue, 8 Jan 2019 18:06:13 +0000 Subject: [PATCH] Returned protection against double completion execution during updates --- .../BaseChatViewController+Changes.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Chatto/Source/ChatController/BaseChatViewController+Changes.swift b/Chatto/Source/ChatController/BaseChatViewController+Changes.swift index db8e03ba1..8e5991e47 100644 --- a/Chatto/Source/ChatController/BaseChatViewController+Changes.swift +++ b/Chatto/Source/ChatController/BaseChatViewController+Changes.swift @@ -173,6 +173,16 @@ extension BaseChatViewController { } } + let myCompletion: () -> Void + do { // Completion + var myCompletionExecuted = false + myCompletion = { + if myCompletionExecuted { return } + myCompletionExecuted = true + completion() + } + } + if usesBatchUpdates { UIView.animate(withDuration: self.constants.updatesAnimationDuration, animations: { () -> Void in self.unfinishedBatchUpdatesCount += 1 @@ -186,7 +196,7 @@ extension BaseChatViewController { collectionView.moveItem(at: move.indexPathOld, to: move.indexPathNew) } }, completion: { [weak self] (_) -> Void in - defer { completion() } + defer { myCompletion() } guard let sSelf = self else { return } sSelf.unfinishedBatchUpdatesCount -= 1 if sSelf.unfinishedBatchUpdatesCount == 0, let onAllBatchUpdatesFinished = self?.onAllBatchUpdatesFinished { @@ -216,7 +226,7 @@ extension BaseChatViewController { } if !usesBatchUpdates || self.updatesConfig.fastUpdates { - completion() + myCompletion() } }