It’s been at least two years since I’ve coded in objective-c, and after pulling my boss’s git repo I found several instances of @property (nonatomic, readonly, weak); in the project.
I felt as though google, stackoverflow, or the apple documentation would be able to solve my query in a jiffy, but I can’t for the life of me what the attribute (weak) does.
My two questions are:
- What does
(weak)mean? - Why is
(weak)not being recognized as a valid keyword by my XCode?
I’m on 10.6 still, but my XCode is up to date.
weakis usable in both Garbage Collection on the desktop, and Automatic Reference Counting on Desktop 10.7+ and iOS 5.0+. It declares that the property is a zeroing weak pointer. In other words, it’s a reference to the object, that does not call retain or release, and is automaticallynilled out when the object is destroyed. In order to use such a property correctly, if you’re going to refer to it more than once, you must store it into a local variable before using it, or it may getnilled out unpredictably in the middle of your code.