There @interface in my @implementation - why?

This is a pretty Nubian question - I look at an example Cocoa code example and there are @interface blocks in the .m files, as well as in the headers. For example, in the header of the AppDelegate class, navigation UIWindow and UI are defined as instance variables, but @property declarations are actually created in the implementation file. Is there a functional reason for this, is it a stylistic choice, or ...?

+4
source share
1 answer

If you just need, for example, some user delegates to work with another class, there is no need to publish the interface in the header.
It simply adds too much noise and makes available interfaces that may not be intended for general use or useful outside the context of the class.

The same applies to class methods and properties - if you want to use declared properties for your instance variables, but do not want them to be publicly available, you do not have to declare them in the header. Class extensions allow you to do this, see, for example, "How to make private property?" .

+7
source

Source: https://habr.com/ru/post/1309469/


All Articles