url(forResource:withExtension:subdirectory:)
Returns the file URL for the resource file identified by the specified name and extension and residing in a given bundle directory.
Declaration
func url(forResource name: String?, withExtension ext: String?, subdirectory subpath: String?) -> URL?Parameters
- name:
The name of a resource file contained in the directory specified by
subpath.If you specify
nil, the method returns the first resource file it finds with the specified extension in that directory. - ext:
The filename extension of the file to locate.
If you specify an empty string or
nil, the extension is assumed not to exist and the file URL is the first file encountered that exactly matchesname. - subpath:
The path of a top-level bundle directory. This must be a valid path. For example, to specify the bundle directory for a Mac app, you might specify the path
/Applications/MyApp.app.
Return Value
The file URL for the resource file or nil if the file could not be located. This method also returns nil if the bundle specified by the bundlePath parameter does not exist or is not a readable directory.
Discussion
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:)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:)