This question already has an answer here:
Class
is a struct pointer, is it a object type or scalar, which I guess is the key to decide to use strong
/weak
or assign
?
This question already has an answer here:
Class
is a struct pointer, is it a object type or scalar, which I guess is the key to decide to use strong
/weak
or assign
?
In Objective-C Class is an object and is instance of a metaclass. It is a retainable object pointer type. Reference: clang.llvm.org also this SO thread.
Lets see different scenario 1.
OUTPUT:
// - Allocate Human
// - Deallocate Human
// Its automatically deallocate because its manage by ARC.
2.
OUTPUT
// - Allocate Human
//Its not deallocate automatically because human class reference count 1 (objHuman1)
OUTPUT
// - Deallocate Human
//Because its referece count is 0
OUTPUT
Allocate Human
Allocate Passport
// Here is magic You can not deallocate passport. Because Human class has Storng reference of Passport.
// But if you declare Weak property of passport variable in Human Class Like:
OUTPUT Will
//Allocate Human
//Allocate Passport
//Deallocate Passport
That's a magic of Week and Strong property. Swift Default property is Strong.