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

# path(forResource:ofType:)

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

```
func path(forResource name: String?, ofType ext: String?) -> String?
```

## 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 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 is the first file encountered that exactly matches     `name`    .

## Return Value

The full pathname for the resource file, or `nil` if the file could not be located.

## Discussion

The method first looks for a matching resource file in the non-localized resource directory of the specified bundle. If a matching resource file is not found, it then looks in the top level of an available language-specific `.lproj` folder. (The search order for the language-specific folders corresponds to the user’s preferences.) It does not recurse through other subfolders at any of these locations. For more 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).

The following code fragment gets the path to a plist within the bundle, and loads it into an `NSDictionary`:

```objc
NSBundle *thisBundle = [NSBundle bundleForClass:[self class]];
if (commonDictionaryPath = [thisBundle pathForResource:@"CommonDictionary" ofType:@"plist"]) {
    theDictionary = [[NSDictionary alloc] initWithContentsOfFile:commonDictionaryPath];
}
```

---

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)