<!--
{
  "availability" : [
    "macOS: 10.7.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSImage/layerContents(forContentsScale:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSImage(im)layerContentsForContentsScale:"
  },
  "title" : "layerContents(forContentsScale:)"
}
-->

# layerContents(forContentsScale:)

Returns an object that may be used as the contents of a layer.

```
func layerContents(forContentsScale layerContentsScale: CGFloat) -> Any
```

## Parameters

`layerContentsScale`

The scale factor for the resulting image. Obtain the value for this parameter by calling the [`recommendedLayerContentsScale(_:)`](/documentation/AppKit/NSImage/recommendedLayerContentsScale(_:)) method.

## Return Value

A object that you can assign to the <doc://com.apple.documentation/documentation/QuartzCore/CALayer/contents> property of a <doc://com.apple.documentation/documentation/QuartzCore/CALayer> object. This object contains the image data from the current image optimized for the specified scale factor.

## Discussion

Use this method in situations where you want to use the image as the contents of a layer. This method provides the image data wrapped in an object that correctly respects all of the possible content gravities supported by the layer. Use of the returned object as the layer’s contents is recommended over the use of the `NSImage` object itself.

---

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)