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

# url(forResource:withExtension:)

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

## Declaration

```swift
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

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

## Discussion

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:)](foundation/bundle/url(forresource:withextension:subdirectory:).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)
- [url(forResource:withExtension:subdirectory:in:)](foundation/bundle/url(forresource:withextension:subdirectory:in:).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)
