<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 8.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URL/withUnsafeFileSystemRepresentation(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation3URLV34withUnsafeFileSystemRepresentationyxxSPys4Int8VGSgKXEKlF"
  },
  "title" : "withUnsafeFileSystemRepresentation(_:)"
}
-->

# withUnsafeFileSystemRepresentation(_:)

Passes the URL’s path in the file system representation to a closure.

```
func withUnsafeFileSystemRepresentation<ResultType>(_ block: (UnsafePointer<Int8>?) throws -> ResultType) rethrows -> ResultType
```

## Parameters

`block`

A closure to execute, which receives a C string as its parameter, and returns a value of a type you choose.

    The parameter passed to the closure is     `nil`     if the URL cannot be represented by the file system. For example, if the URL contains an accented character and the file system only supports ASCII, no file system representation is possible.

## Return Value

The value returned by your closure, if any.

## Discussion

The file system representation is a null-terminated C string with canonical UTF-8 encoding.

> Note:
> The pointer is not valid outside the context of the closure.

---

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)