<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSColor/init(colorSpace:components:count:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSColor(cm)colorWithColorSpace:components:count:"
  },
  "title" : "init(colorSpace:components:count:)"
}
-->

# init(colorSpace:components:count:)

Creates a color object from the specified components of the given color space.

```
init(colorSpace space: NSColorSpace, components: UnsafePointer<CGFloat>, count numberOfComponents: Int)
```

## Parameters

`space`

An `NSColorSpace` object representing a color space. The colorspace should be component-based. The method raises if this is `nil` or a color space that cannot be used with `NSColor` objects.

`components`

An array of the components in the specified color space to use to create the `NSColor` object. The order of these components is determined by the color-space profile, with the alpha component always last. (If you want the created color to be opaque, specify 1.0 for the alpha component.)

`numberOfComponents`

The number of components in the `components` array. This should match the number dictated by the specified color space plus one for alpha. This method raises an exception if they do not match.

## Return Value

The color object.

## See Also

[`usingColorSpace(_:)`](/documentation/AppKit/NSColor/usingColorSpace(_:))

Creates a new color object representing the color of the current color object in the specified color space.



---

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)