Posts

Post not yet marked as solved
1 Replies
276 Views
I have app that is using container for small settings data and iCloud for larger storage, but I also want to be able to save to local documents folder. When I do that the url that is created is not local docs, but: path: file:///var/mobile/Containers/Data/Application/85A8B8C9-C0C3-4843-A74C-5A951F593790/Documents/Dialog08:45,%2022%20Feb%202024 Here is code using to save to local docs folder. func saveDataToFile(data: String) { //file will be datetimedialog let formatter = DateFormatter() formatter.dateFormat = "HH:mm, d MMM y" var dateTime = Date.getCurrentDate() dateTime = formatter.string(from: Date.now) var saveFilename = "Dialog" saveFilename.append(dateTime) let path = getDocumentsDirectory().appendingPathComponent(saveFilename) print("path: \(path)") // let fileURL = URL(fileURLWithPath: data, relativeTo: path) do { try data.write(to: path, atomically: true, encoding: String.Encoding.utf8) } catch { print(error.localizedDescription) } } func getDocumentsDirectory() -> URL { let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) return paths[0] }
Posted
by jpromano.
Last updated
.
Post not yet marked as solved
14 Replies
2.3k Views
I have an app that displays photos from a directory that the user chooses (including children directories).  On launch it checks UserDefaults for stored values, if none from previous run, then asks user to open a directory of photos. Then initializes itself and saves the UserDefaults and also a persistent url so that on subsequent run can re-open directory without user intervention.   When first run and asks for directory, runs fine in setting up app state and saving UserDefaults and persistent url, but when gets to contentView the ImageView fails to show anything, but app continues running for about 15 or 20 sec. changing photo via timer, but no image displayed and then the crash @main hread 1: EXC_BREAKPOINT (code=1, subcode=0x1b8072158) and occurs seemingly async from the running code. Crash report attached. Then if re-launch app, it gets the saved UserDefaults, does set up and the runs fine, displaying images! Can even change directories (in the full app, with window commands which are not in this short version of the app. Crash Report
Posted
by jpromano.
Last updated
.