Skip to content
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

Make assertPossibleRetainCycle more generic #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

func assertPossibleRetainCycle(ofViewController viewController: UIViewController?) {
if viewController == nil { return }
func assertPossibleRetainCycle(for object: AnyObject?) {
if object == nil { return }

// Добавляем задержку в 1 секунду на всякий случай, чтобы точно дать UIKit'у очистить память.
// Если даже через 1 секунду UIKit не очистил память от закрытого экрана, то, вероятно, он утек.
Expand All @@ -14,11 +14,11 @@ func assertPossibleRetainCycle(ofViewController viewController: UIViewController
// разберется, что экран уже закрыт (через логику `isDescribingScreenThatWasAlreadyDismissedWithoutInvokingMarshroute`).
// Однако, в этот момент сам модуль Shelf будет еще в памяти (UIKit его до сих пор не очистит, непонятно почему).
// Поэтому даем UIKit'у время на очистку и откладываем проверку перед ассертом.
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak viewController] in
if let viewController {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak object] in
if let object {
marshrouteAssertionFailure(
"""
It looks like \(viewController as Any) did not deallocate due to some retain cycle!
It looks like \(object as Any) did not deallocate due to some retain cycle!
"""
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public struct ModalPresentationAnimationLaunchingContext {
}

if sourceViewController?.presentedViewController == nil {
assertPossibleRetainCycle(ofViewController: targetViewController)
assertPossibleRetainCycle(for: targetViewController)
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public struct ModalEndpointNavigationPresentationAnimationLaunchingContext {
}

if sourceViewController?.presentedViewController == nil {
assertPossibleRetainCycle(ofViewController: targetNavigationController)
assertPossibleRetainCycle(for: targetNavigationController)
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public struct ModalMasterDetailPresentationAnimationLaunchingContext {
}

if sourceViewController?.presentedViewController == nil {
assertPossibleRetainCycle(ofViewController: targetViewController)
assertPossibleRetainCycle(for: targetViewController)
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public struct ModalNavigationPresentationAnimationLaunchingContext {
}

if sourceViewController?.presentedViewController == nil {
assertPossibleRetainCycle(ofViewController: targetViewController)
assertPossibleRetainCycle(for: targetViewController)
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public struct PushAnimationLaunchingContext {
let targetViewController = targetViewController,
!navigationController.viewControllers.contains(targetViewController)
{
assertPossibleRetainCycle(ofViewController: targetViewController)
assertPossibleRetainCycle(for: targetViewController)
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public struct PopoverPresentationAnimationLaunchingContext {
}

if popoverController?.isPopoverVisible != true {
assertPossibleRetainCycle(ofViewController: targetViewController)
assertPossibleRetainCycle(for: targetViewController)
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct PopoverNavigationPresentationAnimationLaunchingContext {
}

if popoverController?.isPopoverVisible != true {
assertPossibleRetainCycle(ofViewController: targetViewController)
assertPossibleRetainCycle(for: targetViewController)
return true
}

Expand Down