---
title: "url(forResource:withExtension:subdirectory:in:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/bundle/url(forresource:withextension:subdirectory:in:)"
---

# url(forResource:withExtension:subdirectory:in:)

Creates and returns a file URL for the resource with the specified name and extension in the specified bundle.

## Declaration

```swift
class func url(forResource name: String?, withExtension ext: String?, subdirectory subpath: String?, in bundleURL: URL) -> URL?
```

## Parameters

- `name`: The name of the resource file. If you specify nil, the method returns the first resource file it finds that matches the remaining criteria.
- `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 matches name.
- `subpath`: The name of the bundle subdirectory to search.
- `bundleURL`: The file URL of the bundle to search.

## Return Value

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

## See Also

### Finding resource files

- [url(forResource:withExtension:subdirectory:)](foundation/bundle/url(forresource:withextension:subdirectory:).md)
- [url(forResource:withExtension:)](foundation/bundle/url(forresource:withextension:).md)
- [urls(forResourcesWithExtension:subdirectory:)](foundation/bundle/urls(forresourceswithextension:subdirectory:).md)
- [url(forResource:withExtension:subdirectory:localization:)](foundation/bundle/url(forresource:withextension:subdirectory:localization:).md)
- [urls(forResourcesWithExtension:subdirectory:localization:)](foundation/bundle/urls(forresourceswithextension:subdirectory:localization:).md)
- [urls(forResourcesWithExtension:subdirectory:in:)](foundation/bundle/urls(forresourceswithextension:subdirectory:in:).md)
- [path(forResource:ofType:)](foundation/bundle/path(forresource:oftype:).md)
- [path(forResource:ofType:inDirectory:)](foundation/bundle/path(forresource:oftype:indirectory:)-swift.method.md)
- [path(forResource:ofType:inDirectory:forLocalization:)](foundation/bundle/path(forresource:oftype:indirectory:forlocalization:).md)
- [paths(forResourcesOfType:inDirectory:)](foundation/bundle/paths(forresourcesoftype:indirectory:)-swift.method.md)
- [paths(forResourcesOfType:inDirectory:forLocalization:)](foundation/bundle/paths(forresourcesoftype:indirectory:forlocalization:).md)
- [path(forResource:ofType:inDirectory:)](foundation/bundle/path(forresource:oftype:indirectory:)-swift.type.method.md)
- [paths(forResourcesOfType:inDirectory:)](foundation/bundle/paths(forresourcesoftype:indirectory:)-swift.type.method.md)
