a 的每个值是否都
typedef enum
被视为int
?例如,给定以下内容
typedef enum
:// UIView.h typedef enum { UIViewAnimationCurveEaseInOut, UIViewAnimationCurveEaseIn, UIViewAnimationCurveEaseOut, UIViewAnimationCurveLinear } UIViewAnimationCurve;
我如何知道使用哪种方法来创建
NSNumber
?+ (NSNumber *)numberWithShort:(short)value; + (NSNumber *)numberWithUnsignedShort:(unsigned short)value; + (NSNumber *)numberWithInt:(int)value; + (NSNumber *)numberWithUnsignedInt:(unsigned int)value; + (NSNumber *)numberWithLong:(long)value; + (NSNumber *)numberWithUnsignedLong:(unsigned long)value; + (NSNumber *)numberWithLongLong:(long long)value; + (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value; + (NSNumber *)numberWithInteger:(NSInteger)value NS_AVAILABLE(10_5, 2_0); + (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value NS_AVAILABLE(10_5, 2_0);
我认为这
+[NSNumber numberWithInt:]
是正确的使用方法,因为使用 Core Data 实现枚举的最佳方法的公认答案使用了它。例如:[NSNumber numberWithInt:UIViewAnimationCurveLinear]
但是,如果
+[NSNumber numberWithInt:]
是正确的,那为什么呢?对于按位
enum
,例如:enum { UIViewAutoresizingNone = 0, UIViewAutoresizingFlexibleLeftMargin = 1 << 0, UIViewAutoresizingFlexibleWidth = 1 << 1, UIViewAutoresizingFlexibleRightMargin = 1 << 2, UIViewAutoresizingFlexibleTopMargin = 1 << 3, UIViewAutoresizingFlexibleHeight = 1 << 4, UIViewAutoresizingFlexibleBottomMargin = 1 << 5 }; typedef NSUInteger UIViewAutoresizing;
我猜这
+[NSNumber numberWithUnsignedInteger:]
是正确的使用方法,因为有一个明确的NSUInteger
aftertypedef
。正确的?例如:[NSNumber numberWithUnsignedInteger:UIViewAutoresizingNone]
问问题
13209 次