简体   繁体   中英

Do you have to declare overriden @property methods in the .h file?

Beginner question here. In the .h file of an objective c class..

  1. If you have an @ property int someVar; for example.. and you're actually going to write the setter method yourself in the .m file.. do you still have to declare that setter method in the .h file?

  2. If you have some @property declarations in the .h file and you are writing the getters and/or setters yourself.. you don't have to @synthesize them, correct? And if you don't synthesize them, do you have to declare them in the .h file or does the fact that making them properties is sufficient?

  1. No, you don't have to define them since they already are defined. Defining a property implies that there will be a setter method – unless that property is readonly.

  2. Just replace the @synthesize with @dynamic and implement getter and setter yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM