I need to create a separate file for all the constants of my project

In my project, I have a requirement to create a separate file for all the constants that I use in separate classes in one project.

I saw a few examples, but they talk about creating in the .h file, and again they implement them in the .m files. But I only need a ".h'file" to create all the constants, and I have to use all these constants by importing this ".h" file into every class of my project.

Can anyone advise how to solve this ... thanks in advance

+5
source share
3 answers

enter image description here Add a new file.

  • Right click on file inspector
  • select "New file"
  • ios > C ++ > HeaderFile [Figure]
  • #define OK @"OK"
  • View Controller #import "Constants.h" pch, View
  • viewDidLoad NSLog(@"%@",OK);

:)

+12

.h #define , . , .h .m . .

+1

You pretty much answered your question, to the extent that I don't know exactly what you are asking for - you can just create a header file (.h) with your constants and import it into your other classes. You do not need to create the appropriate implementation file (.m). If you use your constants in your code, you can import them into your prefix header and use them automatically.

0
source

All Articles