Issue
This issue is reproducible on iOS 17 beta 4 and iOS 17.0 (21A5303d) public beta.
When try to create a folder using the FileManager
API, the app crashes with the following stack trace.
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “Samples” in the folder “…”." UserInfo={NSURL=file://…/Samples.app/, NSUnderlyingError=0x28100cf00 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
What is the user impact?
Users will not be able to run the app on iOS 17
Steps to Reproduce
- Create a new project
- Add the following code
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.onAppear {
_ = makeTemporaryDirectory()
}
}
/// Creates a temporary directory.
private func makeTemporaryDirectory() -> URL {
try! FileManager.default.url(
for: .itemReplacementDirectory,
in: .userDomainMask,
appropriateFor: Bundle.main.bundleURL,
create: true
)
}
}
- Build and run the app. It crashes on the force try line.
O/S: iOS 17 (Beta 4) / iOS 17.0 (21A5303d)
Device: iPad Pro Gen 4, iPhone 11. Only happens on real device, not on the simulators