1 year ago
#229839
M. Thomas
SwiftUI and iCloud Documents
I am trying to use iCloud with SwiftUI. I just want to be able to read/write json files stored there. I believe I have taken all the proper steps to get there, including the necessary changes to Signings & Capabilities and the addition of settings in info.plist. I have set up iCloud on the simulator. But the following code always returns nil for the URL:
let driveURL = FileManager.default .url(forUbiquityContainerIdentifier:
nil)?.appendingPathComponent("Documents")
if driveURL != nil {
print("iCloud available")
let fileURL = driveURL!.appendingPathComponent("test.txt")
try? "Hello word".data(using: .utf8)?.write(to: fileURL)
} else {
print("iCloud not available")
}
What am I missing?
swift
swiftui
icloud-documents
0 Answers
Your Answer