Bridging to/from CoreFoundation on Linux Bridging to/from CoreFoundation on Linux swift swift

Bridging to/from CoreFoundation on Linux


It looks like I can unsafeBitCast NSString to/from CFString:

import Foundationimport CoreFoundationimport Glibcfunc wantsCFString(_ string: CFString) {        print(string)}let string = "Hello, world!"wantsCFString(unsafeBitCast(string._bridgeToObjectiveC(), to: CFString.self)//prints "Hello, world!"

This makes sense, since CoreFoundation and Foundation types were designed to have the same memory layout -- that's why toll-free bridging works. I'm somewhat surprised that it works with the Swift implementation of Foundation though.