I am using the wahoo fitness API (which is in objective-c) in my swift app. I am trying to combine bitwise multiple items from an enum which is not an NS_ENUM. It is defined as:
typedef enum
{
/** Specifies non-existent sensor. */
WF_SENSORTYPE_NONE = 0,
/** Specifies the bike power sensor. */
WF_SENSORTYPE_BIKE_POWER = 0x00000001,
/** Specifies the bike speed sensor. */
WF_SENSORTYPE_BIKE_SPEED = 0x00000002,
/** Specifies the bike cadence sensor. */
WF_SENSORTYPE_BIKE_CADENCE = 0x00000004,
...
} WFSensorType_t;
The following resulted in: 'WFSensorType_t' is not convertible to 'Bool'
let sensorType = WF_SENSORTYPE_HEARTRATE | WF_SENSORTYPE_BIKE_SPEED | WF_SENSORTYPE_BIKE_CADENCE // WFSensorType_t
The tricky part is that sensorType needs to be passed to another wahoo API object which accepts a WFSensorType_t so I can't wrap the enum into something else otherwise it won't be able to pass it back to the existing API.
Any idea?
You can try:
let sensorType = WF_SENSORTYPE_HEARTRATE.value | WF_SENSORTYPE_BIKE_SPEED.value | WF_SENSORTYPE_BIKE_CADENCE.value
However sensorType will be inferred by Swift as type UInt8. You cannot declare it as WFSensorType_t
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