I am browsing the UIKit framework header files and I see a lot of instances where an anonymous enum is defined followed by a seemingly related typedef. Can someone explain what is going on here?
Does the UIViewAutoresizing type somehow (implicitly) refer to the enum declared in the previous statement? How would you refer to that enum type?
enum {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
typedef NSUInteger UIViewAutoresizing;
The thing is that those are flags intended to use as bit mask, which leads to problems with enums. For example, if it would look like this:
And you would call
setAutoresizingMask:on a view withUIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight, the compiler will complain and you must explicitly typecast it back to theUIViewAutoresizingtype. TheNSUIntegerhowever can take the bit mask.Beside that, everything that lef2 said about
NSUIntegernot being an ObjC object.