---
title: "init(colorSpace:components:count:)"
framework: appkit
role: symbol
role_heading: Initializer
path: "appkit/nscolor/init(colorspace:components:count:)"
---

# init(colorSpace:components:count:)

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

## Declaration

```swift
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

Return Value The color object.

## See Also

### Related Documentation

- [usingColorSpace(_:)](appkit/nscolor/usingcolorspace(_:).md)
