gpt4 book ai didi

objective-c - 从 swift 设置在 objective-c 中声明的位掩码枚举

转载 作者:行者123 更新时间:2023-11-28 11:22:57 25 4
gpt4 key购买 nike

我正在尝试在我的新项目中使用适用于 iOS 的 Parse SDK。它有带有枚举属性的 viewController;

typedef enum {
PFLogInFieldsNone = 0,
PFLogInFieldsUsernameAndPassword = 1 << 0,
PFLogInFieldsPasswordForgotten = 1 << 1,
PFLogInFieldsLogInButton = 1 << 2,
PFLogInFieldsFacebook = 1 << 3,
PFLogInFieldsTwitter = 1 << 4,
PFLogInFieldsSignUpButton = 1 << 5,
PFLogInFieldsDismissButton = 1 << 6,

PFLogInFieldsDefault = PFLogInFieldsUsernameAndPassword | PFLogInFieldsLogInButton | PFLogInFieldsSignUpButton | PFLogInFieldsPasswordForgotten | PFLogInFieldsDismissButton
} PFLogInFields;

根据Objective-C中的教程,我应该这样设置:

 [logInViewController setFields: PFLogInFieldsTwitter | PFLogInFieldsFacebook | PFLogInFieldsDismissButton];

我正在尝试以这种方式进行(使用 swift):

loginViewController.fields = PFLogInFieldsTwitter | PFLogInFieldsFacebook | PFLogInFieldsDismissButton

但我得到错误:“'PFLogInFields' 不可转换为'Bool'”

那么,设置此类属性的正确方法是什么?

最佳答案

Objective-C 中的连续枚举应重构为使用 NS_ENUM,位域枚举应重构为使用 NS_OPTIONS

你应该改变

typedef enum {
//...
} PFLogInFields;

typedef NS_OPTIONS(NSInteger, PFLogInFields) {
//...
};

关于objective-c - 从 swift 设置在 objective-c 中声明的位掩码枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25483411/

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