Enum definition in iOS framework class

I look at the UIKit shell header files, and I see many cases where an anonymous enumeration is defined, followed by apparently the type associated with it. Can someone explain what is going on here?

Is the type of UIViewAutoresizing somehow (implicit) reference to the enumeration declared in the preceding expression? How would you refer to this type of enumeration?

 enum { UIViewAutoresizingNone = 0, UIViewAutoresizingFlexibleLeftMargin = 1 << 0, UIViewAutoresizingFlexibleWidth = 1 << 1, UIViewAutoresizingFlexibleRightMargin = 1 << 2, UIViewAutoresizingFlexibleTopMargin = 1 << 3, UIViewAutoresizingFlexibleHeight = 1 << 4, UIViewAutoresizingFlexibleBottomMargin = 1 << 5 }; typedef NSUInteger UIViewAutoresizing; 
+4
source share
2 answers

The fact is that these are flags intended to be used as a bitmask, which leads to problems with enumerations. For example, if it looks like this:

 typedef enum { UIViewAutoresizingNone = 0, UIViewAutoresizingFlexibleLeftMargin = 1 << 0, UIViewAutoresizingFlexibleWidth = 1 << 1, UIViewAutoresizingFlexibleRightMargin = 1 << 2, UIViewAutoresizingFlexibleTopMargin = 1 << 3, UIViewAutoresizingFlexibleHeight = 1 << 4, UIViewAutoresizingFlexibleBottomMargin = 1 << 5 } UIViewAutoresizing; 

And you would call setAutoresizingMask: in the view using UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight , the compiler will complain, and you must explicitly cast it back to the UIViewAutoresizing type. However, NSUInteger can accept a bitmask.

Also, all that lef2 says about NSUInteger not as an ObjC object.

+3
source

I think that something is wrong here: NSUInteger not an objective-c object, it is an unsigned int for 32-bit systems and an unsigned long for 64-bit systems. So what actually happens is:

 typedef unsigned int UIViewAutoresizing; 

or

 typedef unsigned long UIViewAutoresizing; 

For further reference, I add the following:

 #if __LP64__ || NS_BUILD_32_LIKE_64 typedef long NSInteger; typedef unsigned long NSUInteger; #else typedef int NSInteger; typedef unsigned int NSUInteger; #endif 

Source: CocoaDev

+3
source

Source: https://habr.com/ru/post/1396244/


All Articles