capture-list

Is self captured within a nested function

人盡茶涼 提交于 2019-12-20 11:38:11
问题 With closures I usually append [weak self] onto my capture list and then do a null check on self: func myInstanceMethod() { let myClosure = { [weak self] (result : Bool) in if let this = self { this.anotherInstanceMethod() } } functionExpectingClosure(myClosure) } How do I perform the null check on self if I'm using a nested function in lieu of a closure (or is the check even necessary...or is it even good practice to use a nested function like this) i.e. func myInstanceMethod() { func

Is self captured within a nested function

你说的曾经没有我的故事 提交于 2019-12-20 11:38:02
问题 With closures I usually append [weak self] onto my capture list and then do a null check on self: func myInstanceMethod() { let myClosure = { [weak self] (result : Bool) in if let this = self { this.anotherInstanceMethod() } } functionExpectingClosure(myClosure) } How do I perform the null check on self if I'm using a nested function in lieu of a closure (or is the check even necessary...or is it even good practice to use a nested function like this) i.e. func myInstanceMethod() { func

Is self captured within a nested function

淺唱寂寞╮ 提交于 2019-12-03 01:43:45
With closures I usually append [weak self] onto my capture list and then do a null check on self: func myInstanceMethod() { let myClosure = { [weak self] (result : Bool) in if let this = self { this.anotherInstanceMethod() } } functionExpectingClosure(myClosure) } How do I perform the null check on self if I'm using a nested function in lieu of a closure (or is the check even necessary...or is it even good practice to use a nested function like this) i.e. func myInstanceMethod() { func nestedFunction(result : Bool) { anotherInstanceMethod() } functionExpectingClosure(nestedFunction) } rintaro

How to remove strong reference cycle from closure from method?

孤街醉人 提交于 2019-11-26 18:35:26
问题 Here I have some examples for closure strong reference cycles. If I assign a closure to a stored property, I can use a closure capture list to make the captured reference unowned/weak. But if I assign a method to a stored property closure or assign the method to a closure in the outer scope I can not use a capture list. What can I do to remove the reference cycle in the last two cases? Example to create and avoid strong reference cycle with capture list with closure only internal class