What is the significance of #pragma marks? Why do we need #pragma marks?

前端 未结 7 1393
耶瑟儿~
耶瑟儿~ 2021-01-29 17:21

What is the purpose of #pragma marks in Xcode? Does their location in .m files matter? Should some #pragma come before all others?

7条回答
  •  庸人自扰
    2021-01-29 17:58

    Just to add the information I was looking for: pragma mark is Xcode specific, so if you deal with a C++ project that you open in different IDEs, it does not have any effect there. In Qt Creator, for example, it does not add categories for methods, nor generate any warnings/errors.

    EDIT

    #pragma is a preprocessor directive which comes from C programming language. Its purpose is to specify implementation-dependent information to the compiler - that is, each compiler might choose to interpret this directive as it wants. That said, it is rather considered an extension which does not change/influence the code itself. So compilers might as well ignore it.

    Xcode is an IDE which takes advantage of #pragma and uses it in its own specific way. The point is, #pragma is not Xcode and even Objective-C specific.

提交回复
热议问题