Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine objective-c enum in swift

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?

like image 665
Manuel Darveau Avatar asked Jan 18 '26 21:01

Manuel Darveau


1 Answers

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

like image 83
Anthony Kong Avatar answered Jan 20 '26 14:01

Anthony Kong