gpt4 book ai didi

objective-c - Objective-C 中的新枚举

转载 作者:太空狗 更新时间:2023-10-30 03:09:14 26 4
gpt4 key购买 nike

在最新的工具中,现在允许使用一种新的enum:

typedef enum CarType : NSUInteger {
FourDoorCarType,
TwoDoorCarType
} CarType;

我的问题分为几个部分:

  1. 为什么我应该使用这个而不是旧方法?

  2. 为什么 CarType 出现两次?我尝试跳过第一个 CarType 并将第一行保留为“typedef enum : NSUInteger {”,它似乎工作正常。缺点是什么?

  3. 可以使用NSUInteger以外的一些类型吗?

最佳答案

因为这种新方法可以帮助您实现自动完成、switch 语句、更好、更精确的警告,...

坚持使用宏...

typedef NS_ENUM( NSUInteger, CarType ) {
FourDoorCarType,
TwoDoorCarType
};

... 阅读此示例 https://stackoverflow.com/a/3190470/581190

NSInteger,...你想要什么类型?

关于objective-c - Objective-C 中的新枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11576118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com