diff --git a/Mastodon/Diffiable/Section/ComposeStatusSection.swift b/Mastodon/Diffiable/Section/ComposeStatusSection.swift index 0940ddfa4..46d00dbef 100644 --- a/Mastodon/Diffiable/Section/ComposeStatusSection.swift +++ b/Mastodon/Diffiable/Section/ComposeStatusSection.swift @@ -101,21 +101,24 @@ extension ComposeStatusSection { cell.composeContent .removeDuplicates() .receive(on: DispatchQueue.main) - .sink { text in + .sink { [weak collectionView] text in + guard let collectionView = collectionView else { return } // self size input cell // needs restore content offset to resolve issue #83 let oldContentOffset = collectionView.contentOffset collectionView.collectionViewLayout.invalidateLayout() collectionView.layoutIfNeeded() collectionView.contentOffset = oldContentOffset - + // bind input data attribute.composeContent.value = text } .store(in: &cell.disposeBag) attribute.isContentWarningComposing .receive(on: DispatchQueue.main) - .sink { isContentWarningComposing in + .sink { [weak cell, weak collectionView] isContentWarningComposing in + guard let cell = cell else { return } + guard let collectionView = collectionView else { return } // self size input cell collectionView.collectionViewLayout.invalidateLayout() cell.statusContentWarningEditorView.containerView.isHidden = !isContentWarningComposing @@ -130,7 +133,8 @@ extension ComposeStatusSection { cell.contentWarningContent .removeDuplicates() .receive(on: DispatchQueue.main) - .sink { text in + .sink { [weak collectionView] text in + guard let collectionView = collectionView else { return } // self size input cell collectionView.collectionViewLayout.invalidateLayout() // bind input data @@ -145,9 +149,10 @@ extension ComposeStatusSection { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: ComposeStatusAttachmentCollectionViewCell.self), for: indexPath) as! ComposeStatusAttachmentCollectionViewCell cell.attachmentContainerView.descriptionTextView.text = attachmentService.description.value cell.delegate = composeStatusAttachmentTableViewCellDelegate - attachmentService.imageData + attachmentService.data .receive(on: DispatchQueue.main) - .sink { imageData in + .sink { [weak cell] imageData in + guard let cell = cell else { return } let size = cell.attachmentContainerView.previewImageView.frame.size != .zero ? cell.attachmentContainerView.previewImageView.frame.size : CGSize(width: 1, height: 1) guard let imageData = imageData, let image = UIImage(data: imageData) else { @@ -171,7 +176,8 @@ extension ComposeStatusSection { attachmentService.error.eraseToAnyPublisher() ) .receive(on: DispatchQueue.main) - .sink { uploadState, error in + .sink { [weak cell] uploadState, error in + guard let cell = cell else { return } cell.attachmentContainerView.emptyStateView.isHidden = error == nil cell.attachmentContainerView.descriptionBackgroundView.isHidden = error != nil if let _ = error { @@ -220,7 +226,8 @@ extension ComposeStatusSection { cell.durationButton.setTitle(L10n.Scene.Compose.Poll.durationTime(attribute.expiresOption.value.title), for: .normal) attribute.expiresOption .receive(on: DispatchQueue.main) - .sink { expiresOption in + .sink { [weak cell] expiresOption in + guard let cell = cell else { return } cell.durationButton.setTitle(L10n.Scene.Compose.Poll.durationTime(expiresOption.title), for: .normal) } .store(in: &cell.disposeBag) diff --git a/Mastodon/Scene/Compose/CollectionViewCell/ComposeStatusAttachmentCollectionViewCell.swift b/Mastodon/Scene/Compose/CollectionViewCell/ComposeStatusAttachmentCollectionViewCell.swift index 87fe0efaf..0fa9319d3 100644 --- a/Mastodon/Scene/Compose/CollectionViewCell/ComposeStatusAttachmentCollectionViewCell.swift +++ b/Mastodon/Scene/Compose/CollectionViewCell/ComposeStatusAttachmentCollectionViewCell.swift @@ -57,6 +57,10 @@ final class ComposeStatusAttachmentCollectionViewCell: UICollectionViewCell { _init() } + deinit { + os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function) + } + } extension ComposeStatusAttachmentCollectionViewCell {