<!--
{
  "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/NSString/path(withComponents:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(cm)pathWithComponents:"
  },
  "title" : "path(withComponents:)"
}
-->

# path(withComponents:)

Returns a string built from the strings in a given array by concatenating them with a path separator between each pair.

```
class func path(withComponents components: [String]) -> String
```

## Parameters

`components`

An array of `NSString` objects representing a file path. To create an absolute path, use a slash mark (”`/`”) as the first component. To include a trailing path divider, use an empty string as the last component.

## Return Value

A string built from the strings in `components` by concatenating them (in the order they appear in the array) with a path separator between each pair.

## Discussion

This method doesn’t clean up the path created; use [`standardizingPath`](/documentation/Foundation/NSString/standardizingPath) to resolve empty components, references to the parent directory, and so on.

---

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)