chore(corebluetooth): Use objc2
and its framework crates
#381
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
objc2
is the successor toobjc
, which improves the way memory-management is done using theobjc2::rc::Id
type, which is effectively a typedStrongPtr
. Additionally it provides themsg_send_id!
macro, which ensures that the Objective-C memory management rules are followed correctly. Finally, it has encoding verification when debug assertions are enabled, which verify the calling convention at runtime, and can catch errors with using an incorrect method signature. The second commit fixes the errors that was found with this.Compared to
cocoa
,objc2-foundation
provides type-safe wrappers around each class, which means that you can't accidentally call e.g.allKeys
on something that is not a dictionary, and it allows us to naturally useOption
s for nullable values. The third commit replaces the manual interface to Foundation types insrc/corebluetooth/framework.rs
with the types fromobjc2-foundation
.This PR is only the first part of the transition; in the future we will have
objc2-core-bluetooth
, see madsmtm/objc2#608, which should eliminate the need all ofsrc/corebluetooth/framework.rs
. But in the meantime, this still improves the safety significantly.Feel free to ask if something is unclear!