<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Bundle/url(forResource:withExtension:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSBundle(im)URLForResource:withExtension:"
  },
  "title" : "url(forResource:withExtension:)"
}
-->

# url(forResource:withExtension:)

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

```
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](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents.html#//apple_ref/doc/uid/10000123i-CH104-SW7) in [Bundle Programming Guide](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/Introduction/Introduction.html#//apple_ref/doc/uid/10000123i).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)