swift - Using unowned reference in a closure -


the swift programming language documentation states:

define capture in closure unowned reference when closure , instance captures refer each other, , deallocated @ same time.

so scenario come mind one:

class classwithclosure {   lazy var someclosure: () -> string = {     [unowned self] in     self.mymethod()   }    func mymethod(){    } } 

are there more scenarios closure , instance deallocated @ same time?

anytime classwithclosure instance's reference count hits 0, instance deallocated. since instance getting deallocated, properties deallocated well. anytime classwithclosure instance deallocated, closure deallocated well. can't tell same other way around. mean if set someclosure nil, won't cause deallocation of classwithclosure instance.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -