目标C - 枚举的getter和setter属性 [英] Objective C - Getter and setter properties for enum

查看:244
本文介绍了目标C - 枚举的getter和setter属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我想为其提供getter和setter方法,这样,如果发生事情,我设置 XLInboxManagedMethod to 1.我该怎么做?

解决方案

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

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

然后,您的财产可能如下所示:

  @property(nonatomic,assign)XLBadgeManagedType myEnum; 

其使用可能如下所示:

   - (void)someMethod {

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


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?

解决方案

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...
}

这篇关于目标C - 枚举的getter和setter属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆