CF macro to group functions that have related behavior.
Because structures in C can't have methods, property accessors, or custom initializers, you often need to write such functionality using global functions. Structures in Swift can declare methods, property accessors, and initializers. You use the
CF macro to group together related global functions into a single structure type that's imported into Swift.
Apply CF_SWIFT_NAME to Related Functions
The example below shows several functions that are all related to a
Color type. The
CF macro is applied to each function, giving each one a new name for Swift that's nested together under the
The argument you pass to the
CF macro uses the same syntax as the
#selector expression. You use
self in a
CF argument to refer to the instance that the method belongs to.
Import Related Functions into Swift
Here's how Swift imports the related functions above into a single type: