I’m glad you’re making progress here.
Why did the authors do this?
The answer is rooted in history [1].
One key goal of Mac OS X was a smooth transition from Mac OS 9. Mac OS 9 didn’t have Objective-C, so Foundation wasn’t available there. However, many APIs that were going to be shared between Mac OS 9 and Mac OS X needed Foundation ‘currency’ types, for things like data and strings. To solve this, we rewrote the core of these currency types in C, published that as Core Foundation, and rehosted the Objective-C types of top of those [2].
To make this easier on the Mac OS X side, these currency types were toll-free bridged to their Foundation equivalents. For example, CFData is toll-free bridged to NSData, CFString to NSString, and so on. See see Toll-Free Bridged Types within Core Foundation Design Concepts in the Documentation Archive.
When Swift was introduced one of its key goals was interoperability with Objective-C. Thus it’s easy to convert between Swift’s Data and Foundation’s NSData, and from there CFData
Core Graphics dates to the very beginning of the Mac OS X project. Within Mac OS X there was a low-level layer that could not use Objective-C [3]. Core Graphics was part of that layer. Given that, it has to use Core Foundation ‘currency’ types.
Image I/O was introduced slightly later, but it has similar restrictions.
"public" only!.
I’m not sure what you mean by this, but I wanted to explain how you’d use a UTType in this context, namely:
CGImageDestinationCreateWithData(…, UTType.png.identifier as CFString, …)
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple
[1] Normally I don’t answer why questions — see tip 3 in Quinn’s Top Ten DevForums Tips — but in this case we’re well past the statute of limitations (-:
[2] Note that this was historically true but is no longer true. In the intervening 25 years this has changed twice, with the core implementations moving first to Objective-C and then to Swift. If you’re curious, check out Tony’s talk on this.
[3] Part of the rationale for that was that Objective-C means Foundation and Foundation had a constant and not-insubstantial overhead. Bringing that in to every process was problematic.