Xcode 9.4 documents folder not created in simulator

Hi There,


In our project, we have some frameworks. We recently upgraded our systems to Xcode 9.4.


Given

The app is not installed on the iPhone 8, 11.4 simulator (Xcode 9.4)

We run the tests from one of the frameworks.

When

The tests need access to the documents folder.

We check whether the folder does not exist, if not then we create the new one using:

[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];

Then

The documents folder is created at path:


file:///Users/mac/Library/Developer/CoreSimulator/Devices/59277EA5-68CE-452B-A41A-1A10476D5607/data/Documents/


However, if the app is installed already and we repeat the steps above the documents folder is created at path:


file:///Users/mac/Library/Developer/CoreSimulator/Devices/59277EA5-68CE-452B-A41A-1A10476D5607/data/Containers/Data/Application/3DEFB726-2B6E-47CB-A414-FA068725DC8D/Documents/


This difference in the path is causing our tests to fail and eventually crash during CI stages.

Is there something changed the way "Documents" folder is created in Xcode 9.4 and iOS 11.4 simulator?


This was working perfectly with Xcode 9.2


Any help would be greatly appreciated.

Replies

We have also noticed the exact same issue in our testing.

Same history here, Xcode 10

We have the same issue. The documents folder is missing when running tests

What happen if you get the URL using

-URLForDirectory:inDomain:appropriateForURL:create:error:
and pass
YES
to the
create
parameter?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
This issue still exists when executing unit tests in Xcode 11.6. However, the workaround from eskimo does work for me! Although it is not the Documents directory of the app, a Documents directory will be created and the tests succeed.

Code Block swift
let documentsURL = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)