07-21-2023, 01:47 PM
I am creating a Reddit client for learning purposes. I need to have a file with constants in it. I was thinking about importing the file in the `Reddit-Prefix.pch` file to make the constants available to all the files. **Is it a good way of doing things?** Also, I've done my research and found several methods to create constants, but I don't know which one to use:
- `#define` macro
- `const`
- `static const`
- `extern const`
- `enum`
**So which way is the preferred way? What is the convention?** I know that "it depends" but my question more specifically is: **What are the use cases for each of those solutions?**
Also, if using `extern const`, do I need to import the file, or the constants will be available globally without importing the file?
One thing I could logically conclude is that `enum` is the best choice when defining something like custom error domains (am I actually right?). But what about the others?
- `#define` macro
- `const`
- `static const`
- `extern const`
- `enum`
**So which way is the preferred way? What is the convention?** I know that "it depends" but my question more specifically is: **What are the use cases for each of those solutions?**
Also, if using `extern const`, do I need to import the file, or the constants will be available globally without importing the file?
One thing I could logically conclude is that `enum` is the best choice when defining something like custom error domains (am I actually right?). But what about the others?