Contents

embedInCode(_:)

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

Declaration

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]
}

See Also

Applying Rules