views:

3686

answers:

3

If you have Class A with an instance var "foo" which has a @property/@synthesize directive, and Class B inherits from Class A, does it also need to @property/@synthesize "foo"? The reason I ask is because when I try to use Class B's "foo", the calling class says that "foo" is not something of a structured union or a member, which makes me believe it needs to be explicitly synthesized.

+3  A: 

No, you don't. Synthesized properties are added to class A and it's subclasses automatically.

Georg
@Georg: The downvote is mine, but I assure you it was not intentional! I clicked the down arrow by accident, and now the vote is "too old to change". If you would be so kind as to make a small edit, I will happily switch it to an upvote (which is what I intended to do in the first place).
e.James
@e.James: done. :)
Georg
@Georg: Thanks. That's been weighing on my conscience! :)
e.James
A: 

WHen inheriting you should not need to redeclare any properties or variables.

Perhaps if you post your ClassB header file or a portion of then people can better pinpoint your problem.

Andrew Grant
+4  A: 

If you have Class A with an instance var "foo" which has a @property/@synthesize directive, and Class B inherits from Class A, does it also need to @property/@synthesize "foo"?

No.

The reason I ask is because when I try to use Class B's "foo", the calling class says …

No, the compiler says it.

… that "foo" is not something of a structured union or a member, which makes me believe it needs to be explicitly synthesized.

It is. In class A.

The compiler is giving you that warning because it doesn't know about the @property, which is because you have neither declared it nor imported a header that declares it. You say that class A's header declares the property, so import class A's header into class B's implementation, so that the compiler knows about the property when compiling class B.

Peter Hosey