You can put the following code snippet into the Xcode playground
import CoreFoundation
class MyData {
let someInt = 1
}
let a = MyData() //Definition of the varialbe a
print(CFGetRetainCount(a)) // it prints out 2
}
The only thing the code does is initialize an object of type MyData
and assign it to a constant named a
I thought it would be only 1 reference (the constant a) "points to" the object, however, it turns out the object already has 2 references "point to" it.
Question:
Who is this second reference?
If the constant a is deallocated/destroyed then the object will not be deallocated because there is still a reference "points to" the object. (I guess my understanding is wrong, please point out any errors)
Thanks