Skip to content

Support for CoreBluetooth changes by iOS15#10

Open
jooyyy wants to merge 2 commits intocodeinversion:masterfrom
jooyyy:master
Open

Support for CoreBluetooth changes by iOS15#10
jooyyy wants to merge 2 commits intocodeinversion:masterfrom
jooyyy:master

Conversation

@jooyyy
Copy link

@jooyyy jooyyy commented Sep 23, 2021

No description provided.

@netizen01
Copy link
Contributor

Thanks! Let me do a quick check on this and I'll merge.

/// :nodoc:
public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
guard let service = services[characteristic.service.uuid.uuidString] else { return }
guard let service = services[characteristic.service?.uuid.uuidString ?? ""] else { return }
Copy link

@jlevine22 jlevine22 Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought but would it logically make more sense to use guard to check for the service/uuidString instead of defaulting to an empty string?

guard let uuidString = characteristic.service?.uuid.uuidString, let service = services[uuidString] else { return }

Functionally I think they're about the same but it seems weird you might try to access a service with the uuid of ""

Copy link
Contributor

@netizen01 netizen01 Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the service param change from an optional? you can't access a map value with an optional key, hence the ""

Edit: ... I think the service param here became an optional, so the "" is necessary.

... this might be weird...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is a callback from CoreBluetooth. You're already indexing services by uuid. If for some reason CB sends you an update for a service without a UUID, you're basically screwed, so, I'd say ignore it.

        guard let serviceUUID = characteristic.service?.uuid.uuidString else { return }
        guard let service = services[serviceUUID] else { return }

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

Successfully merging this pull request may close these issues.

4 participants