I've written an method that does some graphics calculations. There, you can specify a start-direction like "from left", "from right", "from bottom", "from top".
Now I don't want the user of my method to pass confusing values like 1, 2, 3 or 4 or even strings. Nothing like that. Instead, I would like to create constants like:
kFromLeft, kFromRight, kFromTop, kFromBottom
I've seen this in an Apple header file:
enum CGImageAlphaInfo {
kCGImageAlphaNone,
kCGImageAlphaPremultipliedLast,
kCGImageAlphaPremultipliedFirst,
kCGImageAlphaLast,
kCGImageAlphaFirst,
kCGImageAlphaNoneSkipLast,
kCGImageAlphaNoneSkipFirst,
kCGImageAlphaOnly
};
typedef enum CGImageAlphaInfo CGImageAlphaInfo;
Five things I dont understand here / which are unclear to me:
1) Why is there a semicolon separating the definition from the typedef?
2) Why do they repeat CGImageAlphaInfo like a parot?
3) If I would put something like this in my header file, I would say in my method that the type of the parameter is CGImageAlphaInfo (of course I'll have a different name), right?
4) I would normally specify the values for those constants in a way like that? (example):
#define kCGImageAlphaNone 100
#define kCGImageAlphaPremultipliedLast 300
#define kCGImageAlphaPremultipliedFirst 900
5) Am I required to set those constants to such stupid values? Or could I just check inside my method which constant got passed in, like
if(paramConst == kCGImageAlphaNone) {...}
?