<!--
{
  "availability" : [
    "SwiftPM: 5.9.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "PackageDescription",
  "identifier" : "/documentation/PackageDescription/Resource/embedInCode(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "PackageDescription"
    ],
    "preciseIdentifier" : "s:18PackageDescription8ResourceV11embedInCodeyACSSFZ"
  },
  "title" : "embedInCode(_:)"
}
-->

# embedInCode(_:)

Applies the embed rule to a resource at the given path.

```
static func embedInCode(_ path: String) -> Resource
```

## Parameters

`path`

The path for a resource.

## Return Value

A `Resource` instance.

## Discussion

Use the embed rule to embed the bytes that represent the contents of a resource into executable code.
For example,  if you embed the file `identifier.txt` that has the contents:

```
Hello Swift
```

Package manager generates a PackageResources class with each embedded resource as a static property based on the name of the resource.
For the example above, the code generated by Package Manager is equivalent to the following source:

```
struct PackageResources {
    static let identifier_txt: [UInt8] = [72,101,108,108,111,32,83,119,105,102,116,10]
}
```

---

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)