I'm writing a tool which would benefit from knowing which of a class' instance variables are declared __weak
.
This information must exist somewhere at runtime, but is there any way of accessing it, documented or otherwise? (It's for a tool, so I don't care so much about it breaking with updates)
Alright, here is a sample implementation, using a custom object implementation, that does a rudimentary check to see if an iVar is weak or not:
The above code is meant to be used with ARC enabled, while the following custom object code is not:
This ONLY works for weak iVars. With a
unsafe_unretained
variable, it will give a false positive, my best guess for this is because__weak
information is saved at runtime whilstunsafe_unretained
information is not.I hope this helps!