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
extensionis an empty string ornil, the extension is assumed not to exist and the file URL is the first file encountered that exactly matchesname.
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
url(forResource:withExtension:subdirectory:)urls(forResourcesWithExtension:subdirectory:)url(forResource:withExtension:subdirectory:localization:)urls(forResourcesWithExtension:subdirectory:localization:)url(forResource:withExtension:subdirectory:in:)urls(forResourcesWithExtension:subdirectory:in:)path(forResource:ofType:)path(forResource:ofType:inDirectory:)path(forResource:ofType:inDirectory:forLocalization:)paths(forResourcesOfType:inDirectory:)paths(forResourcesOfType:inDirectory:forLocalization:)path(forResource:ofType:inDirectory:)paths(forResourcesOfType:inDirectory:)