URL(fileURLWithPath:) behavior change in iOS 26 - Tilde (~) in filename causes unexpected path resolution

Environment:

  • Xcode 26
  • iOS 26
  • Also tested on iOS 18 (working correctly)

Description:

I'm experiencing a behavior change with URL(fileURLWithPath:) when the filename starts with a tilde (~) character.

On iOS 18, passing a filename like ~MyFile.txt to URL(fileURLWithPath:) treats the tilde as a literal character. However, on iOS 26, the same code resolves the tilde as the home directory, resulting in unexpected output.

Minimal Example:

  let filename = "~MyFile.txt"                                                                                                                                       
  let url = URL(fileURLWithPath: filename)                                                                                                                           
  print(url.lastPathComponent)                                                                                                                                       

Expected Result (iOS 18):
~MyFile.txt

Actual Result (iOS 26):
924AF0C4-C3CD-417A-9D5F-733FBB8FCF29

The tilde is being resolved to the app's container directory, and lastPathComponent returns the container UUID instead of the filename.

Questions:
1. Is this an intentional behavior change in iOS 26? 2. Is there documentation about this change? 3. What is the recommended approach for extracting filename components when the filename may contain special characters like ~?

Workaround:

Using NSString.lastPathComponent works correctly on both iOS versions:

 let filename = "~MyFile.txt"                                                                                                                                       
  let result = (filename as NSString).lastPathComponent                                                                                                              
  // Returns: "~MyFile.txt" ✅                                                                                                                                       

Is this the recommended approach going forward?

I won't believe this is an intentional change. Do you have a feedback report yet? If not, would you mind to file one and share your report ID here? Thanks.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

URL(fileURLWithPath:) behavior change in iOS 26 - Tilde (~) in filename causes unexpected path resolution
 
 
Q