-2

I'm using BeaconKit to detect near beacons around.

I want to check if the beacon detected is of type AltBeacon. My code is showing an error because of the matching expression I'm using.

if beacon.beaconType == AltBeacon { print("Detected an AltBeacon") } 

Here is the error message I'm getting

Binary operator == cannot be applied to operands of type Int' and AltBeacon.Type

What can I use instead so I can correct my matching expression please ! Thank you

1

2 Answers 2

1

Have you tried

if beacon.beaconType is AltBeacon { print("Detected an AltBeacon") } 

or instead, you can check

if let beacon.beaconType as? AltBeacon { print("Detected an AltBeacon") } else { // handle } 
Sign up to request clarification or add additional context in comments.

1 Comment

Actually according to the source code both if expressions will always evaluate to false.
1

The error is clear. beaconType is an Int. It cannot be compared with anything else but an Int

Two possible solutions:

  1. Figure out the integer value of AltBeacon (2 is just an example) and compare

    if beacon.beaconType == 2 { ... 
  2. As AltBeacon is a subclass of Beacon check the type of the instance

    if beacon is AltBeacon { ... 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.