Contents

url(forResource:withExtension:)

Returns the file URL for the resource identified by the specified name and file extension.

Declaration

func url(forResource name: String?, withExtension ext: String?) -> URL?

Parameters

  • name:

    The name of the resource file.

    If you specify nil, the method returns the first resource file it finds with the specified extension.

  • ext:

    The extension of the resource file.

    If extension is an empty string or nil, the extension is assumed not to exist and the file URL is the first file encountered that exactly matches name.

Return Value

The file URL for the resource file or nil if the file could not be located.

Discussion

If extension is an empty string or nil, the returned pathname is the first one encountered where the file name exactly matches name. For details on how localized resources are found, read The Bundle Search Pattern in Bundle Programming Guide.

See Also

Finding Resource Files