What method rule is declared in Obj-c? Can I use the method without declaration directly?

In Xcode4.4, I found that I could use the define method in a .m file directly without declaring it in a .h head or .m file.

what is the method declaration rule in obj-c? Can I use the method without declaration in the main file?

+6
source share
2 answers

If you declare a method in the header file, other classes will be able to access this method.

+3
source

You import headers when you want to use the methods declared in the headers.

So, if you created a class called ObjectA to use the methods that you specified in ObjectA.h , you need to import it #import "ObjectA.h" .

Usually you only need to import .m implementation files. If you need it in the header file, you can use the @class annotation as follows:

 @class ObjectA ... @property (nonatomic, strong) ObjectA *objectA; 
0
source

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


All Articles