When I was beginning to teach myself objective c a few months ago (I'm still pretty new) I noticed in some examples of header files that had a few properties that referred to instance variables that were not defined in the @interface declaration block. Here's an example:
As you see, valueB has nothing defined in the interface declaration block but there's no compile warnings. The app I've been coding hasn't really defined anything between those brackets and everything seems to work fine. So what's the deal? Do properties automatically define instance variables that aren't there? Will not declaring instance variables in both places have a different effect? I can't find any information about this, perhaps because I don't know what to search for. Can someone clear my confusion?
Did you @synthesize them in the implementation? @property doesn't actually do anything, it only describes how the accessor methods should be synthesized.
Did you @synthesize them in the implementation? @property doesn't actually do anything, it only describes how the accessor methods should be synthesized.
For the legacy runtimes, instance variables must already be declared in the @interface block of the current class. If an instance variable of the same name and compatible type as the property exists, it is used—otherwise, you get a compiler error.
For the modern runtimes (see Runtime Versions and Platforms in Objective-C Runtime Programming Guide), instance variables are synthesized as needed. If an instance variable of the same name already exists, it is used.
So, if an iVar doesn't exist synthesize will create it. For the sake of clarity I'd still prefer to declare it upfront.