Sobes.tech
Junior — Middle

If you create a variable user with weak var user = User(), how many references to this object will it have?

sobes.tech AI

Answer from AI

When declaring a variable as weak var user = User() in Swift, the User() object is created, but the variable user references it weakly (weak). Since there are no strong references to this object, it will be deinitialized and freed from memory immediately. Therefore, there are no strong references to the User object, and the variable user will be nil.

In summary: the number of strong references to the object is 0, the object is immediately deleted, and user becomes nil.

If you create a variable user with weak var user =… - sobes.tech