Search code examples
objective-cenumsswiftparse-platformbit-masks

Setting bitmask enum declared in objective-c from swift


I'm trying to use Parse SDK for iOS in my new project. It has viewController with enum property;

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;

According to tutorial in Objective-C I should set it in this way:

 [logInViewController setFields: PFLogInFieldsTwitter | PFLogInFieldsFacebook | PFLogInFieldsDismissButton];

I'm trying to do it in this way(using swift):

loginViewController.fields = PFLogInFieldsTwitter | PFLogInFieldsFacebook | PFLogInFieldsDismissButton

But I get error:"'PFLogInFields' is not convertible to 'Bool'"

So, what is the correct way to set such kind of properties?


Solution

  • I had the same problem as you. See this answer for how to set PFLogInFields in Swift. It worked for me!!