Objective C - 枚举的 getter 和 setter 属性

发布于 2024-11-27 02:43:31 字数 266 浏览 2 评论 0原文

我是 Objective-C 的新手。我有一个枚举,如下:

typedef enum _XLBadgeManagedType {
    XLInboxManagedMethod = 0,
    XLDeveloperManagedMethod = 1
} XLBadgeManagedType ;

我想要它的 getter 和 setter 方法,这样如果发生某些情况,我将 XLInboxManagedMethod 设置为 1。我将如何去做呢?

I am a complete newbie at Objective-C. I have an enum as follows:

typedef enum _XLBadgeManagedType {
    XLInboxManagedMethod = 0,
    XLDeveloperManagedMethod = 1
} XLBadgeManagedType ;

I want to have getter and setter methods for it, such that if something happens, I set XLInboxManagedMethod to 1. How would I go about doing it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤寂小茶 2024-12-04 02:43:31

您的代码只是定义一个枚举类型。它是一个静态的、编译时常量,不会改变。您可以通过声明枚举的实例,然后将其更改为您定义的常量值之一来使用枚举。如果您的枚举如下所示:

typedef enum _XLBadgeManagedType {
    XLInboxManagedMethod = 0,
    XLDeveloperManagedMethod = 1
} XLBadgeManagedType;

那么您的属性可能如下所示:

@property (nonatomic, assign) XLBadgeManagedType myEnum;

并且其用途可能如下所示:

- (void)someMethod {

    self.myEnum = XLInboxManagedMethod;
    self.myEnum = XLDeveloperManagedMethod;
    // etc...
}

Your code is just defining an enum type. It's a static, compile-time constant that is not changed. You use enums by declaring an instance of one, then changing it to one of the constant values you defined. If your enum looks like:

typedef enum _XLBadgeManagedType {
    XLInboxManagedMethod = 0,
    XLDeveloperManagedMethod = 1
} XLBadgeManagedType;

Then your property could look like:

@property (nonatomic, assign) XLBadgeManagedType myEnum;

And its use may look like:

- (void)someMethod {

    self.myEnum = XLInboxManagedMethod;
    self.myEnum = XLDeveloperManagedMethod;
    // etc...
}
埋葬我深情 2024-12-04 02:43:31

您不更改枚举的值。他们保持原样。

You do not change the values of enums. They stay as they are.

好倦 2024-12-04 02:43:31

它们是符号常量。你无法改变它。

They are symbolic constants. You can not change it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文