<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSSound/init(contentsOf:byReference:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSSound(im)initWithContentsOfURL:byReference:"
  },
  "title" : "init(contentsOf:byReference:)"
}
-->

# init(contentsOf:byReference:)

Initializes the receiver with the audio data located at a given URL.

```
init?(contentsOf url: URL, byReference byRef: Bool)
```

## Parameters

`url`

URL to the sound file with which the receiver is to be initialized.

`byRef`

When <doc://com.apple.documentation/documentation/Swift/true> only the name of the sound is stored with the `NSSound` instance when archived using <doc://com.apple.documentation/documentation/Foundation/NSCoding/encode(with:)>; otherwise the audio data is archived along with the instance.

## Return Value

Initialized `NSSound` instance.

## Discussion

---

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)