---
title: Bundling resources with a Swift package
framework: swift-package-manager
role: article
role_heading: Article
path: swift-package-manager/documentation/packagemanagerdocs/bundlingresources
---

# Bundling resources with a Swift package

Add resource files to your Swift package and access them in your code.

## Overview

Overview If you declare // swift-tools-version: 5.3 or later in your Package.swift file, you can bundle resources alongside your source code in Swift packages. For example, Swift packages can contain asset catalogs, test fixtures, and so on. Add resource files Package manager treats non-source files found in the target’s sources directory as assets, scoped to that target. For example, any resources for the MyLibrary target reside by default in Sources/MyLibrary. To easily distinguish resources from source files, create and use a subfolder for the resources. For example, put all resource files into a directory named Resources, resulting in all of your resource files residing at Sources/MyLibrary/Resources. Explicitly declare or exclude resources To add a resource that the compiler doesn’t handle automatically, explicitly declare it as a resource in your package manifest. If you’re building your package with Xcode, it automatically handles a number of kinds of resources. For example, to include a file text.txt as a resource, add the file into Sources/MyLibrary/Resources. Then explicitly declare it as a package resource by adding the name of the file to the list of resources for your target: targets: [     .target(         name: "MyLibrary",         resources: [             .process("Resources/text.txt")]     ), ] The example above uses  process(_:localization:) to identify the resource. When you explicitly declare a resource, choose a rule to determine how Swift treats the resource file. The options include: If a file resides inside a target’s folder and you don’t want it to be a package resource, pass it to the target initializer’s exclude parameter. For example, if you have a file called instructions.md in the sources directory, meant only for local use and not intended to be bundled, use exclude: targets: [     .target(         name: "MyLibrary",         exclude:["instructions.md"]     ), ] In general, avoid placing files that aren’t resources in a target’s source folder. If that’s not feasible, avoid excluding every file individually, place all files you want to exclude in a directory, and add the directory path to the array of excluded files. Swift Package Manager warns you about files it doesn’t recognize in a target’s Sources directory. Access a resource in code If a target includes resources, the compiler creates a resource bundle and an internal static extension on Bundle to access it for each module. Use the extension to locate package resources. For example, use the following to retrieve the URL to a property list you bundle with your package: let settingsURL = Bundle.module.url(forResource: "settings", withExtension: "plist") important: Always use Bundle.module to access resources. A package shouldn’t make assumptions about the exact location of a resource. If you want to make a package resource available to apps that depend on your Swift package, declare a public constant for it. For example, use the following to expose a property list file to apps that use your Swift package: let settingsURL = Bundle.module.url(forResource: "settings", withExtension: "plist")

## See Also

### Guides

- [Creating a Swift package](swift-package-manager/documentation/packagemanagerdocs/creatingswiftpackage.md)
- [Setting the Swift tools version](swift-package-manager/documentation/packagemanagerdocs/settingswifttoolsversion.md)
- [Adding dependencies to a Swift package](swift-package-manager/documentation/packagemanagerdocs/addingdependencies.md)
- [Resolving and updating dependencies](swift-package-manager/documentation/packagemanagerdocs/resolvingpackageversions.md)
- [Creating C language targets](swift-package-manager/documentation/packagemanagerdocs/creatingclanguagetargets.md)
- [Using build configurations](swift-package-manager/documentation/packagemanagerdocs/usingbuildconfigurations.md)
- [Packaging based on the version of Swift](swift-package-manager/documentation/packagemanagerdocs/swiftversionspecificpackaging.md)
- [Releasing and publishing a Swift package](swift-package-manager/documentation/packagemanagerdocs/releasingpublishingapackage.md)
- [Generating Software Bill of Materials (SBOM)](swift-package-manager/documentation/packagemanagerdocs/generatingsboms.md)
- [Continuous Integration Workflows](swift-package-manager/documentation/packagemanagerdocs/continuousintegration.md)
- [Plugins](swift-package-manager/documentation/packagemanagerdocs/plugins.md)
- [Module Aliasing](swift-package-manager/documentation/packagemanagerdocs/modulealiasing.md)
- [Using a package registry](swift-package-manager/documentation/packagemanagerdocs/usingswiftpackageregistry.md)
- [Package Collections](swift-package-manager/documentation/packagemanagerdocs/packagecollections.md)
- [Using shell completion scripts](swift-package-manager/documentation/packagemanagerdocs/usingshellcompletion.md)
