Core Foundation

{{Short description|C application programming interface in Mac OS X}}

{{Use mdy dates|date=October 2013}}

{{Infobox software

| name = Core Foundation

| title = Core Foundation

| logo =

| logo caption =

| screenshot =

| caption =

| collapsible =

| developer = Apple Inc.

| released =

| discontinued =

| latest release version =

| latest release date =

| latest preview version =

| latest preview date =

| repo = {{URL|https://github.com/apple/swift-corelibs-foundation}}

| programming language = Swift, Objective-C, C

| operating system = {{Plainlist|

}}

| platform =

| size =

| language =

| genre = System library

| license = APSL 2.0

| alexa =

| website = {{URL|https://developer.apple.com/documentation/corefoundation|developer.apple.com}}

}}

Core Foundation (also called CF) is a C application programming interface (API) written by Apple Inc. for its operating systems, and is a mix of low-level routines and wrapper functions. Most Core Foundation routines follow a certain naming convention that deal with opaque objects, for example CFDictionaryRef for functions whose names begin with CFDictionary, and these objects are often reference counted (manually) through CFRetain and CFRelease. Internally, Core Foundation forms the base of the types in the Objective-C standard library and the Carbon API.{{cite web |last1=ridiculous_fish |title=Bridge |url=https://ridiculousfish.com/blog/posts/bridge.html |date=2006}}

The most prevalent use of Core Foundation is for passing its own primitive types for data, including raw bytes, Unicode strings, numbers, calendar dates, and UUIDs, as well as collections such as arrays, sets, and dictionaries, to numerous macOS C routines, primarily those that are GUI-related. At the operating system level Core Foundation also provides standardized application preferences management through CFPropertyList, bundle handling, run loops, interprocess communication through CFMachPort and CFNotificationCenter, and a basic graphical user interface message dialog through CFUserNotification.

Other parts of the API include utility routines and wrappers around existing APIs for ease of use. Utility routines perform such actions as file system and network I/O through CFReadStream, CFWriteStream, and CFURL and endianness translation (Byte Order Utilities). Some examples of wrapper routines include those for Core Foundation's wrapper routines for Unix sockets, the CFSocket API.

Some types in Core Foundation are "toll-free bridged", or interchangeable with a simple cast, with those of their Foundation Kit counterparts. For example, one could create a CFDictionaryRef Core Foundation type, and then later simply use a standard C cast to convert it to its Objective-C counterpart, NSDictionary *, and then use the desired Objective-C methods on that object as one normally would.

Core Foundation has a plug-in model ({{mono|CFPlugin}}) that is based on the Microsoft Component Object Model.{{cite web | title=Plug-ins and Microsoft's COM | url=https://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFPlugIns/Concepts/com.html#//apple_ref/doc/uid/20001158-CJBEJBHH | work=Mac Developer Library | publisher=Apple Inc | archive-url=https://web.archive.org/web/20140901084753/https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFPlugIns/Concepts/com.html | archive-date=2014-09-01 | access-date=2015-03-25}}

Open source availability

Apple used to release most of CF as an open-source project called CFLite that can be used to write cross-platform applications for macOS, Linux, and Windows.{{Cite web|url=http://opensource.apple.com/source/CF/|title = Source Browser}}

A third-party open-source implementation called OpenCFLite extends the Apple CFLite for building on 32-bit Windows and Linux environments. It is maintained by one of the WebKit developers, but was stalled by 2015.[http://sourceforge.net/projects/opencflite/ OpenCFLite project on SourceForge]. The karaoke platform KJams maintains a fork since 2017. This version, by its programmer David M. Cotter, supports 64-bit systems and has a CFNetwork implementation with LibreSSL-based TLS.{{cite web |title=CFLite |url=https://karaoke.kjams.com/wiki/CFLite |website=KJams |access-date=19 February 2020}} A fork of OpenCFLite was created by Grant Erickson (an original collaborator with Brent Fulgham on the SourceForge version) in 2021{{cite web |title=OpenCFLite project on GitHub |website=GitHub |url=http://github.com/gerickson/opencflite/ |access-date=30 November 2021}} with a companion port of the CFHost portion of CFNetwork, as OpenCFNetwork.{{cite web |title=OpenCFNetwork project on GitHub |website=GitHub |url=http://github.com/gerickson/opencfnetwork/ |access-date=30 November 2021}}

The Swift Corelib Foundation, a fallback version of the Foundation Kit for the Swift programming language for non-Apple platforms, contains a near-full version of the Core Foundation released under Apache License 2.0.{{cite web |title=swift-corelibs-foundation|website=GitHub|date=October 14, 2021|url=https://github.com/apple/swift-corelibs-foundation}}

GNUstep includes a version of the Core Foundation called "libs-corebase".{{cite web |title=gnustep/libs-corebase: The GNUstep CoreBase Library is a library of general-purpose, non-graphical C objects. |url=https://github.com/gnustep/libs-corebase/ |website=GitHub |publisher=GNUstep |date=19 November 2019}}

See also

References

{{reflist}}