Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use immediate force unwrap on discovery #8

Closed
sindresorhus opened this issue Apr 17, 2024 · 1 comment
Closed

Don't use immediate force unwrap on discovery #8

sindresorhus opened this issue Apr 17, 2024 · 1 comment

Comments

@sindresorhus
Copy link

This crashes in some situations: https://github.com/exPHAT/SwiftBluetooth/blob/c5a9f4e5d6d1ffc312ffe26ea1760dc9a9a9673f/Sources/SwiftBluetooth/Peripheral/Peripheral.swift#L31C30-L31C39

When retrieving the device from central.retrievePeripherals(withIdentifiers: [uuid]).

@exPHAT
Copy link
Owner

exPHAT commented Apr 17, 2024

This should be fixed in the #3 merge yesterday with a commit that was added last minute. The crash would happen if you connect -> disconnect -> central.retrievePeripherals(). I've added a test case to confirm it's fixed for now.

Feels wrong to even have an implicitly-unwrapped Optional in the repo. I would like to remove it altogether. I don't see a scenario where you access a peripheral that wasn't first "discovered", meaning a standard Optional wouldn't be needed either. If that is true, I could add the Peripheral.discovery to the initializer but it would force that same assumption on all delegate methods that will need to wrap a CBPeripheral -> Peripheral.

If you have any input, I'm open to it!

@exPHAT exPHAT closed this as completed Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants