<!--
{
  "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:localization:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSBundle(im)URLForResource:withExtension:subdirectory:localization:"
  },
  "title" : "url(forResource:withExtension:subdirectory:localization:)"
}
-->

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

Returns the file URL for the resource identified by the specified name and file extension, located in the specified bundle subdirectory, and limited to global resources and those associated with the specified localization.

```
func url(forResource name: String?, withExtension ext: String?, subdirectory subpath: String?, localization localizationName: String?) -> 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.

`localizationName`

The language ID for the localization. This parameter should correspond to the name of one of the bundle’s language-specific resource directories without the `.lproj` extension.

## Return Value

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

## Discussion

This method is equivalent to [`urls(forResourcesWithExtension:subdirectory:)`](/documentation/Foundation/Bundle/urls(forResourcesWithExtension:subdirectory:)), except that only nonlocalized resources and those in the language-specific `.lproj` directory specified by `localizationName` are searched.

There should typically be little reason to use this method—see Getting the Current Language and Locale. See also [`preferredLocalizations(from:forPreferences:)`](/documentation/Foundation/Bundle/preferredLocalizations(from:forPreferences:)) for how to determine what localizations are available.

---

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)