url(for:asLocalizedFor:)
Returns a URL for the specified relative path.
Declaration
nonisolated func url(for path: FilePath, asLocalizedFor language: Locale.Language) throws -> URLParameters
- path:
The relative path.
- language:
The language that the framework uses to limit the search within localized asset packs.
Mentioned in
Return Value
The URL to the item.
Discussion
All asset packs share the same namespace, so you can treat the overall collection of downloaded asset packs as if it were a single root directory that contains all of your subdirectories and asset files, regardless of the specific asset pack in which any particular file resides. Unlike contents(at:asLocalizedFor:options:) and descriptor(for:asLocalizedFor:), this method supports retrieving entire directories—including packages—in which case it merges the corresponding slices of the shared logical directory from all downloaded asset packs that are localized in the specified language and that contain such slices. If there’s a path collision across multiple such asset packs, then it’s undefined from which asset pack an individual file will be resolved.
This method is most useful if you intentionally induce a file-path collision across multiple differently localized asset packs. For example, you may include an English-localized version of Videos/Introduction.m4v in an en asset pack, a Hebrew-localized version of Videos/Introduction.m4v in a he asset pack, and an American Spanish–localized version of Videos/Introduction.m4v in an es-US asset pack. If you offer split-language functionality to users, then you may want to download two or more of those asset packs on the same device. In that scenario, the specific choice of item the URL to which url(for:) returns would be undefined. With this method, merely passing a Locale.Language instance to the language parameter is sufficient to resolve the ambiguity. url(for:) is more suitable in most other situations.