<!--
{
  "availability" : [
    "macOS: 10.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSColorSpace/init(cgColorSpace:)-889nv",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSColorSpace(im)initWithCGColorSpace:"
  },
  "title" : "init(cgColorSpace:)"
}
-->

# init(cgColorSpace:)

Initializes and returns a color space object initialized from a Core Graphics color-space object.

```
init?(cgColorSpace: CGColorSpace)
```

## Parameters

`cgColorSpace`

A reference to a Core Graphics color-space object (<doc://com.apple.documentation/documentation/CoreGraphics/CGColorSpace>).

## Return Value

The initialized `NSColorSpace` object or `nil` if initialization was not successful, which might happen if the color space represented by the `CGColorSpace` object is not supported by `NSColorSpace`.

## Discussion

Because `NSColorSpace` might retain or copy the `CGColorSpace` object depending on circumstances, you should not assume pointer equality of the provided object with that returned by [`cgColorSpace`](/documentation/AppKit/NSColorSpace/cgColorSpace). And even if the pointer equality is preserved during runtime, it may not be after the `NSColorSpace` object is archived and unarchived.

---

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)