I\'m working with the Facebook Objective-C SDK in Swift and I\'m trying to compare an FBSessionState value with a value from the enum. However I get the compiler error:
You could unwrap the enum and constants with '.value' to get the underlying integer, which should be switchable:
switch x.value {
case Foo.value:
}
Maybe this is a bug and apple fix it in future releases.
Swift automatically maps Obj-C enums to its own style of enumName.caseName
structure. For example, if the enum
is named FBSessionState
and there is the FBSessionStateOpen
case, it will map as FBSessionState.Open
in Swift.
The ==
operator will work for comparing Swift enums.
With the Beta4 update, the .value workaround no longer works. There doesn't seem to be another easy workaround without changing Facebook's SDK.
I changed all the Facebook enums to use the NS_ENUM macro, so that you can use Swift syntax the enums.
if FBSession.activeSession().state == .CreatedTokenLoaded
These changes were merged into pgaspar's Facebook fork, which includes other fixes for Swift compatibility.
pod 'Facebook-iOS-SDK', :git => 'https://github.com/pgaspar/facebook-ios-sdk.git'
Adding to Nikolai Nagorny's answer, this is what worked for me:
if (device.deviceType.value == TYPE_BLUETOOTHNA.value)