Declare properties in .h interface or in an extension in .m file?

前端 未结 1 1676
执念已碎
执念已碎 2020-12-29 09:33

In Objective-C, is it best practice to:

  1. Declare objects such as buttons in the .h and then synthesize in the .m

    .h
    @interface SomeViewCo         
    
    
            
相关标签:
1条回答
  • 2020-12-29 09:45

    First, as of Xcode 4.4 there is no longer a need to @synthesize(unless you change both the setter and getter method), either when the @property is declared in the @interface or @implementation.

    If the @property is only accessed from within the class then declare the @property in a class extension in the .m file. This provides encapsulation and make it easy to see that the @property is not used from another class.

    If the @property is used by other classes, by design, then define it in the @interface in the .h file.

    0 讨论(0)
提交回复
热议问题