简体   繁体   中英

Declaring methods in .h file

if i want to create a helper method in my .m file. its call it -(void) helpMeDoSomething... etc. do i need to declare the function prototype in the .h file like in c/c++ or just declaring it in the .m file is enough

Neither C, C++, nor Objective-C require function declarations to be in the header file. They simply have to be declared before they are used, and the definition in the .m file can serve as the declaration.

In order for other classes to see the method, its signature must be in the header file. If you are using the method in the same class that it is defined in, it does not need to be in the header file.

Put the prototype in the .h file if you want to make it available to be called from code in other files. You can put it in the .m file if it will only be called from inside that one file.

与在C / C ++中一样,您可以在.m文件中声明它,只要在使用它之前就声明了它,而且只要不需要在其他地方使用它即可。

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