Trying to incorporate Parse into a new Swift project.
When I get to this block:
logInViewController.fields = PFLogInFieldsUsernameAndPassword | PFLogInFieldsLogInButton | PFLogInFieldsSignUpButton | PFLogInFieldsPasswordForgotten
I'm getting this error in XCode 6:
Could not find an overload for '|' that accepts the supplied arguments
Anyone happen to know what's wrong with that syntax?
Use the .value
then use the result to create a PFLogInFields
instance:
logInViewController.fields = PFLogInFields(PFLogInFieldsUsernameAndPassword.value
| PFLogInFieldsLogInButton.value)
Timothy's answer is right but it is better to correct the code with Swift's update.
logInViewController.fields = PFLogInFields(rawValue:
PFLogInFieldsUsernameAndPassword.rawValue |
PFLogInFieldsLogInButton.rawValue)
Second way:
You can use operator overloading for shorter code:
func +=(inout slf: PFLogInFields,other: PFLogInFields)-> PFLogInFields{
slf = PFLogInFields(rawValue: slf.rawValue | other.rawValue)!
}
func +(a: PFLogInFields, b: PFLogInFields)-> PFLogInFields{
return PFLogInFields(rawValue: a.rawValue | b.rawValue)!
}
And further:
logInViewController.fields = .UsernameAndPassword + .LogInButton
or
logInViewController.fields = .UsernameAndPassword
logInViewController.fields += .LogInButton
In Swift 2 it seems that the accepted solution or other answers don't work. I solved my problem by enclosing the PFLogInFields in an array. Everything seems to work just fine.
So instead of:
loginViewController.fields = PFLogInFields.UsernameAndPassword | PFLogInFields.LogInButton | PFLogInFields.PasswordForgotten | PFLogInFields.SignUpButton | PFLogInFields.Facebook | PFLogInFields.Twitter
I wrote:
loginViewController.fields = [PFLogInFields.UsernameAndPassword, PFLogInFields.LogInButton, PFLogInFields.PasswordForgotten, PFLogInFields.SignUpButton, PFLogInFields.Facebook, PFLogInFields.Twitter]
Seems this is a moving target, as none of the answers here seem to work anymore. At present I have to use this:
logInViewController.fields = PFLogInFields.UsernameAndPassword | PFLogInFields.LogInButton
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With