<!--
{
  "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:subdirectory:in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSBundle(cm)URLForResource:withExtension:subdirectory:inBundleWithURL:"
  },
  "title" : "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.

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

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

## Discussion

---

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)