Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of @synthesize/@property in Objective-C inheritance

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.

like image 493
Coocoo4Cocoa Avatar asked Feb 22 '09 16:02

Coocoo4Cocoa


People also ask

Why We Use synthesize in Objective C?

@synthesize tells the compiler to take care of the accessor methods creation i.e it will generate the methods based on property description. It will also generate an instance variable to be used which you can specify as above, as a convention it starts with _(underscore)+propertyName.

What is synthesize Objective C?

@synthesize creates a getter and a setter for the variable. This lets you specify some attributes for your variables and when you @synthesize that property to the variable you generate the getter and setter for the variable. The property name can be the same as the variable name.

Which is the default for synthesized properties?

Default Synthesis Of Properties Clang provides support for autosynthesis of declared properties. Using this feature, clang provides default synthesis of those properties not declared @dynamic and not having user provided backing getter and setter methods.

Why @property and @synthesize do not exist for a property in Swift?

Swift provides no differentiation between properties and instance variables (i.e, the underlying store for a property). To define a property, you simply declare a variable in the context of a class. A swift class is simply a ClassName.


1 Answers

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

like image 110
Georg Schölly Avatar answered Sep 22 '22 08:09

Georg Schölly