<!--
{
  "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/appendingPathComponent(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(im)stringByAppendingPathComponent:"
  },
  "title" : "appendingPathComponent(_:)"
}
-->

# appendingPathComponent(_:)

Returns a new string made by appending to the receiver a given string.

```
func appendingPathComponent(_ str: String) -> String
```

## Parameters

`str`

The path component to append to the receiver.

## Return Value

A new string made by appending `aString` to the receiver, preceded if necessary by a path separator.

## Discussion

The following table illustrates the effect of this method on a variety of different paths, assuming that `aString` is supplied as “`scratch.tiff`”:

|Receiver’s String Value|Resulting String     |
|-----------------------|---------------------|
|“`/tmp`”               |“`/tmp/scratch.tiff`”|
|“`/tmp/`”              |“`/tmp/scratch.tiff`”|
|“`/`”                  |“`/scratch.tiff`”    |
|“” (an empty string)   |“`scratch.tiff`”     |

Note that this method only works with file paths (not, for example, string representations of URLs).

---

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)