<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGFunction",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Graphics"
    ],
    "preciseIdentifier" : "c:@T@CGFunctionRef"
  },
  "title" : "CGFunction"
}
-->

# CGFunction

A general facility for defining and using callback functions.

```
class CGFunction
```

## Overview

These functions can take an arbitrary number of floating-point input values and pass back an arbitrary number of floating-point output values.

Core Graphics uses function objects to implement shadings. [`CGShading`](/documentation/CoreGraphics/CGShading) describes the parameters and semantics required for the callbacks used by function objects.

## Topics

### Creating Function Objects

[`init(info:domainDimension:domain:rangeDimension:range:callbacks:)`](/documentation/CoreGraphics/CGFunction/init(info:domainDimension:domain:rangeDimension:range:callbacks:))

Creates a Core Graphics function.

### Retaining and Releasing CGFunction Objects

[`CGFunctionRelease`](/documentation/CoreGraphics/CGFunctionRelease)

Decrements the retain count of a function object.

[`CGFunctionRetain`](/documentation/CoreGraphics/CGFunctionRetain)

Increments the retain count of a function object.

### Callbacks

[`CGFunctionCallbacks`](/documentation/CoreGraphics/CGFunctionCallbacks)

A structure that contains callbacks needed by a `CGFunctionRef` object.

[`CGFunctionEvaluateCallback`](/documentation/CoreGraphics/CGFunctionEvaluateCallback)

Performs custom operations on the supplied input data to produce output data.

[`CGFunctionReleaseInfoCallback`](/documentation/CoreGraphics/CGFunctionReleaseInfoCallback)

Performs custom clean-up tasks when Core Graphics deallocates a `CGFunctionRef` object.

### Working with Core Foundation Types

[`typeID`](/documentation/CoreGraphics/CGFunction/typeID)

Returns the type identifier for Core Graphics function objects.

## See Also

  [Quartz 2D Programming Guide](https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html#//apple_ref/doc/uid/TP30001066)



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)