promisekit states following on their website:
should concerned retain cycles?
tl;dr: it’s safe use self in promise handlers.
this safe:
somepromise.then { self.dosomething() }
provided
somepromise
resolves, function passedthen
released, specifying[weak self]
not necessary.specifying [unowned self] dangerous.
you’re telling me not worry retain cycles?!
no, it’s default not going cause retain cycles when using promisekit. still possible...
does mean should never use [weak self]
in promisekit blocks? there ever situations still need use [weak self]
? how preventing retain cycle?
that documentation merely saying don't have worry promisekit introducing "strong reference cycles" (previously known "retain cycles") because when promise fulfilled , block finishes running, strong references automatically resolved you. choice of strong vs weak references solely you.
for example, there's no need keep strong reference dismissed view controller if updating ui elements on scene no longer exists. you'd use weak
in scenario. want strong reference (e.g. may want update underlying model reflect success or failure of promise).
bottom line, they're saying shouldn't let promisekit dictate strong vs weak references, rather should driven app's broader design requirements. hard rule re promisekit should avoid unowned
.
Comments
Post a Comment