SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.3k stars 742 forks source link

RetainCycle when select case "case viewController(_: UIViewController)" #359

Closed VladislavHERZ closed 4 years ago

VladislavHERZ commented 4 years ago

Select "case viewController(_: UIViewController)", and set duration == .forever. When dismiss or pop vc, we get retain cycle.

wtmoose commented 4 years ago

If you say .forever, it is up to you to call `hide at some point. Are you expecting it to auto-detect when you’re finished with the view and auto-hide?

VladislavHERZ commented 4 years ago

Yes, when vc will be destroyed, need to destroy view(Alert), this process should be automatically. Alert don't should keep vc.

wtmoose commented 4 years ago

I'll think about it. in the meantime, you can call hide in your view controller's disappearance method.

wtmoose commented 4 years ago

Assuming I make this a weak reference, SwiftMessages still needs to update it's internal bookkeeping in order to present the next message in the queue via some kind of auto-dismiss based on the VC being deallocated. How would you propose that SwiftMessages detects when your view controller is deallocated?

VladislavHERZ commented 4 years ago

Try this, but this code will be work only with vc.

struct WeakVCWrapper<Element:UIViewController> {
    weak var value:Element?

    init(_ value:Element) {
        self.value = value
    }
}

Or

struct WeakWrapper<Element:AnyObject> {
    weak var value:Element?

    init(_ value:Element) {
        self.value = value
    }
}

But you will need to cast to your type class use "as?".

wtmoose commented 4 years ago

The question was how would you propose detecting when the view controller is deallocated (not how to make a weak reference)? As I said, SwiftMessages needs to update its internal bookkeeping when the VC is deallocated in order to show the next message.