Should Objective-C constants be wrapped by an implementation block?

I have an iOS application that I am writing. I stepped away #defineto create my constant values. I have a few questions regarding the use of these style declarations:NSString *const segueToMainMenu

  • If I use them internally, I put them in a .m file. However, should they be placed inside @implementationor outside the block, or does it matter? I think inside, because they are implementation-specific, not global, but I'm not sure. Any details are appreciated.

  • If I create a more global scope using a keyword externand I use a couple of Constants files (Constants.h / Constants.m), do I need to place them in @interfaceand then define them in the section @implementation? What is the advantage of this and the old way of using the Constants.h file and including it in other headers? Why do I need two files now?

  • Is it standard practice to still name constants with the prefix "k" (for example, kAnimationDuration), or should I now do something like MainMenuViewControllerAnimationDuration? I imagine that yes, and if so, does it matter for the constants of the number 1 (i.e., not extern), as I call them? In other words, are those visible outside my implementation?

Clarification is much appreciated.

+4
1

, , - , .

k . - <prefix><name>, "MDSomeConstant".

+5

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


All Articles