sorry if it's a silly question. I just started learning swift. I mainly use php for my daily job. Apple Store's Swift textbook uses the following example (i modified it into a shorter version) to demonstrate the usage of weak reference:
class Person {
var apartment: Apartment?;
}
class Apartment {
weak var tenant: Person?;
}
var john: Person?; john = Person();
var number73: Apartment?; number73 = Apartment();
john!.apartment = number73; number73!.tenant = john; //circular reference here
john = nil; number73 = nil; //deference from static variable names
In the above Apartment class definition, if the weak key word is removed from var tenant, it creates a strong reference cycle in the following code so that the two instances do not get disposed by GC. However, it appears to me the GC really does not need the indication of the weak reference. It is obvious that the two instances can not be linked from any variables in the current scope or from any static variables, so they are safe to be disposed.
Why dose Swift force the syntax? The only advantage I can figure out is the weak key word highlights the logic so the code is easier to read.