Код: Выделить всё
DocumentGroup(editing: Entry.self, contentType: .myDocument) {
MainWindowView()
}
< /code>
В моем Mainwindowview я использую < /p>
@Environment(\.documentConfiguration) private var documentConfiguration
< /code>
Чтобы получить URL -адрес для URL -файла ModelDocument, созданного пользователем модели.func saveReferencedData(_ data: Data, documentURL: URL?) throws {
let logger = Logger(subsystem: "saveReferencedData", category: "Asset")
if let documentURL {
let referencedFileName = "\(entryIdentifier)_\(assetIdentifier).\(assetType)"
let tempFileURL = documentURL.appending(components: referencedFileName)
if documentURL.startAccessingSecurityScopedResource() {
do {
try data.write(to: tempFileURL, options: [])
} catch {
documentURL.stopAccessingSecurityScopedResource()
throw AssetFileOperationError.unableToSaveReferenceFile
}
self.referencedFileLocation = referencedFileName
logger.debug("Successfully saved image data to: \(referenceFileURL)")
}
documentURL.stopAccessingSecurityScopedResource()
} else {
logger.debug("ERROR! Unable to save referenced image file because document URL is nil.")
}
}
Большое спасибо за чтение.
Подробнее здесь: https://stackoverflow.com/questions/786 ... le-package
Мобильная версия