I am creating a Reddit client for learning purposes. It needs to be filmed with a fixed file. I was thinking about importing a file in the How is the preferred way? What is the conference? I know that "it depends" but my question is more specifically: What are the use cases for all those solutions? In addition, if you are using One thing I can logically conclude is that The first question is whether you want a constant, which is actually two questions: If they are internal and specific to a single class, then declare them as If they belong to one class but should be public / used by other classes, declare them as If they should be global, declare them in a header and define them in the related module, especially for those constants. You can keep them in different modules, continuously with different levels, how much global you want, and for different global constants that you do not meet with each other , With each their own header, if you want. > The old answer is "There is no type of information in macros", but today the composers are smart. The modern answer is because the debugger will not know about your macro. You can not say in the OK, rmaddy has defeated me in this comment: Code> Enum can only define an integer constants such as serial identifier number, bit-mask, four-byte code etc. . For those purposes, I was thinking about importing the file in the Reddit-Prefix.pch file to make available the constants for all files to make it work Is there a good way? Maybe harmless, but possibly excessive. What are the cases of using those solutions? In addition, if you are using You need to import the file, either each file In the case where you import the file, use it or in the prefix header. reddit-prefix.pch file to create an available constant for all files. Is this a good way to do the job? In addition, I did my research and found several methods to create constants, but I do not know who will use:
#define
const
static const
extern const Li>
enum
external consultant , do I need to import the file, or import the file without stabilizing the globally Will it be available?
Enum is the best option when defining something like a custom error domain (am I really right ?) But what about others?
constitute constant at the top of the .m file, such as:
Fixed NSString * const MyThingNotificationKey = @ "MyThingNotificationKey";
extern in the written form on top and in them Define. Me:
// External Extension NSString * const MyThingNotificationKey; //.m NSString * const MyThingNotificationKey = @ "MyThingNotificationKey";
Why not
#define ?
[myThing addObserver: self forKey: MyThingNotificationKey] command if a
MyThingNotificationKey is a macro; The debugger can only know about it that it is a variable.
Why not
enum ?
enum is great and you should use it at all. (Even better, use.) For other things, you should use something else;
enum does nothing to integers.
and other questions
#defined : very limited I honestly do not know that there is a good reason to use it for constants.
const : Besides the best for the local constraint, you have to use it to declare it in a header and now it's defining it.
Static Constance : The best for file-specific (or class-specific) constants. / Li>
External Constance : It should be used when exporting constantly in the header.
extern
No comments:
Post a Comment