What is the best way to handle toll free bridging ...
# ios
l
What is the best way to handle toll free bridging in Kotlin/Native? I have a method that returns NSData, and I need to pass this to a method that accepts CFDataRef. These types can be toll free bridged, but I can’t figure out how to do so in Kotlin, since casting doesn’t work.
r
You can use
CFBridgingRetain
to convert
NSData
to
CFDataRef
, and
CFBridgingRelease
to go the other way. Note that you can create memory leaks if you retain things without releasing them via either
CFBridgingRelease
or
CFRelease
.
l
Thanks. It seems like the secure enclave library is accepting the data now. Now I just have to figure out why the query returns no key found right after I create the key... Good to know that the bridging is working, though.
I see you're actually using the same secure key library. I'll have to look more through the code.
r
Make sure you're checking the status codes you get back. Lots of subtle little errors that can happen if you pass the wrong arguments to some of those functions.
l
I just got it to a point where I can read the text errors from the generate key pair method (not that they were as helpful as I'd hoped) and fixed the -50 telling me the params were wrong. Now the key gen method returns success, but the query returns -25300 (not found). I'll have to spend some more time debugging it later.
The CFDictionary params are a bit frustrating. It's times like this when I remember why I stopped developing for iOS a few years back with my side projects. KMM's got me wanting to get back into iOS dev, though.
r
Yeah every interaction with CoreFoundation is like some eldritch incantation.
p
175 Views