---
title: pathComponents
framework: foundation
role: symbol
role_heading: Instance Property
path: foundation/nsstring/pathcomponents
---

# pathComponents

The file-system path components of the receiver.

## Declaration

```swift
var pathComponents: [String] { get }
```

## Discussion

Discussion The strings in the array appear in the order they did in the receiver. If the string begins or ends with the path separator, then the first or last component, respectively, will contain the separator. Empty components (caused by consecutive path separators) are deleted. For example, this code excerpt: NSString *path = @"tmp/scratch"; NSArray *pathComponents = [path pathComponents]; produces an array with these contents:  |   |   |  If the receiver begins with a slash—for example, “/tmp/scratch”—the array has these contents:  |   |   |   |  If the receiver has no separators—for example, “scratch”—the array contains the string itself, in this case “scratch”. Note that this method only works with file paths—not, for example, string representations of URLs.

## See Also

### Related Documentation

- [components(separatedBy:)](foundation/nsstring/components(separatedby:)-238fy.md)

### Working with Paths

- [path(withComponents:)](foundation/nsstring/path(withcomponents:).md)
- [completePath(into:caseSensitive:matchesInto:filterTypes:)](foundation/nsstring/completepath(into:casesensitive:matchesinto:filtertypes:).md)
- [fileSystemRepresentation](foundation/nsstring/filesystemrepresentation.md)
- [getFileSystemRepresentation(_:maxLength:)](foundation/nsstring/getfilesystemrepresentation(_:maxlength:).md)
- [isAbsolutePath](foundation/nsstring/isabsolutepath.md)
- [lastPathComponent](foundation/nsstring/lastpathcomponent.md)
- [pathExtension](foundation/nsstring/pathextension.md)
- [abbreviatingWithTildeInPath](foundation/nsstring/abbreviatingwithtildeinpath.md)
- [appendingPathComponent(_:)](foundation/nsstring/appendingpathcomponent(_:).md)
- [appendingPathExtension(_:)](foundation/nsstring/appendingpathextension(_:).md)
- [deletingLastPathComponent](foundation/nsstring/deletinglastpathcomponent.md)
- [deletingPathExtension](foundation/nsstring/deletingpathextension.md)
- [expandingTildeInPath](foundation/nsstring/expandingtildeinpath.md)
- [resolvingSymlinksInPath](foundation/nsstring/resolvingsymlinksinpath.md)
- [standardizingPath](foundation/nsstring/standardizingpath.md)
