Shane,
I never though of adding them. In that case I assume each enum has only a single 1 in the binary number and the sum of the bits forms a bit mask.
The Apple docs for NSDateComponentsFormatterUnitsStyle say “Constants for specifying how to spell out unit names.” But that same page below has “typedef enum NSDateComponentsFormatterUnitsStyle : NSInteger {”
How can I tell look at the declaration below and tell if they represents bits.
typedef enum NSDateComponentsFormatterUnitsStyle : NSInteger {
NSDateComponentsFormatterUnitsStylePositional = 0,
NSDateComponentsFormatterUnitsStyleAbbreviated,
NSDateComponentsFormatterUnitsStyleShort,
NSDateComponentsFormatterUnitsStyleFull,
NSDateComponentsFormatterUnitsStyleSpellOut,
NSDateComponentsFormatterUnitsStyleBrief
} NSDateComponentsFormatterUnitsStyle;
If I click the NSDateComponentsFormatterUnitsStylePositional link on the same page it brings up a new page that says the value is equal to zero. But none of the other links for the other enums say what the value is.
I tried reading the value directly in AppleScript with:
-- Line 1
current application's NSDateComponentsFormatterUnitsStyleAbbreviated as integer
-- Line 2
(current application's NSDateComponentsFormatterUnitsStyleAbbreviated) + 1
-- Line 3
set TheVar to (current application's NSDateComponentsFormatterUnitsStyleAbbreviated) + 1
-- Line 4
TheVar
Which produces pretty weird results.
Line 1 doesn’t produce an error but also produces no result. In line 2 I can add 1 to the value of the enum and I don’t get an error but I also get no result. In line 3 I can set the value of a variable to the enum + 1 and when the value of the variable is read it does produce a result which is one.
set TheVar2 to (current application's NSDateComponentsFormatterUnitsStyleShort) + 0
TheVar2 -->
set TheVar2 to (current application's NSDateComponentsFormatterUnitsStyleAbbreviated) + 0
TheVar2 --> 1
set TheVar2 to (current application's NSDateComponentsFormatterUnitsStyleShort) + 0
TheVar2 --> 2
set TheVar2 to (current application's NSDateComponentsFormatterUnitsStyleFull) + 0
TheVar2 --> 3
set TheVar2 to (current application's NSDateComponentsFormatterUnitsStyleSpellOut) + 0
TheVar2 --> 4
-- But the 2 lines below both return errors saying they can't get the value for the enum
-- TheVar2 to (current application's NSDateComponentsFormatterUnitsStyleBrief) + 0
-- set TheVar2 to (current application's NSDateComponentsFormatterUnitsStyle) + 0
set TheVar2 to (current application's NSDateComponentsFormatterUnitsStyleBrief) + 0
TheVar2 --> 3
set TheVar2 to (current application's NSDateComponentsFormatterUnitsStyle) + 0
TheVar2 --> 3
The second list of examples implies the enum values were 1, 2, 3, 4, error, error. This does not suggest they are number with a single bit set. But if that is true then adding them together makes no sense.
How can I find the value of an enum? Is there a way to tell if these enums are numbers with just a single bit set? Is adding the values of enums something you do because the method only calles for a single input and I need multiple enums to specify what I want?
Bill