<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGFont/init(_:)-9aour",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core Graphics",
      "CoreGraphics"
    ],
    "preciseIdentifier" : "c:@F@CGFontCreateWithDataProvider"
  },
  "title" : "init(_:)"
}
-->

# init(_:)

Creates a font object from data supplied from a data provider.

```
init?(_ provider: CGDataProvider)
```

## Parameters

`provider`

A data provider.

## Return Value

The font object or `NULL` if the font can’t be created. In Objective-C, you’re responsible for releasing this object using [`CGFontRelease`](/documentation/CoreGraphics/CGFontRelease).

## Discussion

Before drawing text in a Core Graphics context, you must set the font in the current graphics state by calling the function [`setFontSize(_:)`](/documentation/CoreGraphics/CGContext/setFontSize(_:)).

---

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)