I would like to use ReferenceFileDocument or FileDocument but the file type I use is a package type that conforms to com.apple.package.
However the FileDocument and ReferenceFileDocument respective write methods are called with a inout FileWrapper.
I need this this FileWrapper to be a directory FileWrapper so that i can add child items to it. However the write method is being called with a regularFile instance of the FileWrapper so i am unable to add nested files that I need within my package.
My writableContentTypes is UTType(exportedAs: "com.example.package", conformingTo: .package). And my Xcode project expires/declares this data type as a package, so that UIDocument/NSDocument work.
However the FileDocument and ReferenceFileDocument respective write methods are called with a inout FileWrapper.
I need this this FileWrapper to be a directory FileWrapper so that i can add child items to it. However the write method is being called with a regularFile instance of the FileWrapper so i am unable to add nested files that I need within my package.
My writableContentTypes is UTType(exportedAs: "com.example.package", conformingTo: .package). And my Xcode project expires/declares this data type as a package, so that UIDocument/NSDocument work.
Hi hishnash! SwiftUI provides you with a default value for the FileWrapper that is suitable for most developers' needs. Because the FileWrapper parameter is inout, you can replace it with a new one that is directory-based when you are writing a package to disk:
If you think there's room to improve this API, I encourage you to let the SwiftUI team know via the Feedback Assistant!
Code Block swift func write(to fileWrapper: inout FileWrapper, contentType: UTType) throws { let children: [String : FileWrapper] = <# construct your file hierarchy here #> fileWrapper = FileWrapper(directoryWithFileWrappers: children) }
If you think there's room to improve this API, I encourage you to let the SwiftUI team know via the Feedback Assistant!