iOS Swift: anonymous instance not used

Problem:

method of anonymous instance not called.

let dest = SomeController()
dest.modalPresentationStyle = .custom
//new instance, animationController will not be called
detail.transitioningDelegate = SomeDelegate() 
present(detail, animated: true, completion: nil)

Cause:

weak reference

Solution:

extract instance to class property

...
fileprivate let mDelegate = SomeDelegate()
...
let dest = SomeController()
dest.modalPresentationStyle = .custom
detail.transitioningDelegate = self.mDelegate
present(detail, animated: true, completion: nil)

你可能感兴趣的:(iOS Swift: anonymous instance not used)