Why might this code not work?
Using XCode 11.3.1 and Swift 5
I am getting an error stating that Value of type 'Int' has no member 'intValue' as it relates to device.rssi. What have I missed?
MetaWearScanner.shared.startScan(allowDuplicates: true) { (device) in
// We found a MetaWear board, see if it is close
if device.rssi.intValue > -50 {
// Hooray! We found a MetaWear board, so stop scanning for more
MetaWearScanner.shared.stopScan()
// Connect to the board we found
device.connectAndSetup().continueWith { t in
if let error = t.error {
// Sorry we couldn't connect
print(error)
} else {
// Hooray! We connected to a MetaWear board, so flash its LED!
var pattern = MblMwLedPattern()
mbl_mw_led_load_preset_pattern(&pattern, MBL_MW_LED_PRESET_PULSE)
mbl_mw_led_stop_and_clear(device.board)
mbl_mw_led_write_pattern(device.board, &pattern, MBL_MW_LED_COLOR_GREEN)
mbl_mw_led_play(device.board)
}
}
}
}
Comments
Title
I am getting an error stating that Value of type 'Int' has no member 'intValue' as it relates to device.rssi.
Board Information
Provide the following information about your hardware:
Hardware revision [0.4]
Firmware revision [1.5.0]
Model number [5]
If unsure, use the MetaBase app's board diagnostic screen.
Host Device Information:
Model Name: MacBook Pro Running Mojave
Description
Answer these questions:
What is the expected behavior? That I would be able to use the demo code.
What is observed behavior?
I am getting an error stating that Value of type 'Int' has no member 'intValue' as it relates to device.rssi.
What is the set of steps that produces the observed behavior? Copy the code below into a project
We should be able to follow these steps and observe the same behavior
Make sure you also post data that demonstrates your issue. Don't just only tell us about the problem.
Below is a screenshot as requested:
SDK
Since developers have their own coding style, projects and environments, SDK issues will probably be more difficult to nail down. As such, it will greatly speed up discussions if you can provide us with more details than usual.
In particular, please give us the:
SDK version: 3.4.2
Development platform / Runtime environment: XCode 11.3.1 and Swift 5
Self contained piece of metawear SDK calls that replicates the issue
We should able to copy/paste the code and run it ourselves with minimal effort
MetaWearScanner.shared.startScan(allowDuplicates: true) { (device) in
// We found a MetaWear board, see if it is close
if device.rssi.intValue > -50 {
// Hooray! We found a MetaWear board, so stop scanning for more
MetaWearScanner.shared.stopScan()
// Connect to the board we found
device.connectAndSetup().continueWith { t in
if let error = t.error {
// Sorry we couldn't connect
print(error)
} else {
// Hooray! We connected to a MetaWear board, so flash its LED!
var pattern = MblMwLedPattern()
mbl_mw_led_load_preset_pattern(&pattern, MBL_MW_LED_PRESET_PULSE)
mbl_mw_led_stop_and_clear(device.board)
mbl_mw_led_write_pattern(device.board, &pattern, MBL_MW_LED_COLOR_GREEN)
mbl_mw_led_play(device.board)
}
}
}
}
BRUSH UP ON YOUR SWIFT. THIS IS NOT AN SDK ERROR!!! THIS IS ABOUT SWIFT SYNTAX!!
Look at the rssi type and fix your code.