UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Exporting multiple File types

Forums > SwiftUI

Hey there everyone, I'm back with a different issue that I recently discovered in an app of mine.

My app is a checkbook ledger app that I made to help track finances and such, which I am glad to have done, due to GnuCash acting up after upgrading to macOS 12, but I noticed after a recent update I published that the main export option was not working, while the other export option that I recently added was not.

This is not too big of a deal for people like me, since I know where the database backend is stored and made it publicly accessible on the iOS app, whereas the macOS version puts in a not so easy to access location, but considering that some of the users of the app are not that tech savy or knowledgable, in addition to likely lazy in reading README files, this is likely going to hurt the experience.

Does anybody know of the proper way to export multiple formats in SwiftUI?

In my code, seeing as the documentation from Apple and such did not provide anyway to pass an array of UITypes to fileExporter, like it does for fileImporter, I thought adding a second fileExporter and a second state variable to deal with that exporter and add the newly supported file type to that in both the main view for the iOS app and the app for macOS, but, unknown to me until now, it stopped working.

I tried search around or Google, coming up details talked about in this post and a few other places, but when I tried implementing it, XCode, which currently version 13.2.1, complained that exportFiles could not be found in environment values.

If you would like to see the code for yourself, it can be found the address below:

https://github.com/bryceac/BCheckbook

the main views, where I believe the issue occurs, are called Contentiew.swift and are found in the iOS folder and macOS folder in the repository.

1      

Ok, it looks like this was simpler to fix than I thought.

For those that need help, the file wrapper in a ReferenceFileDocument should be implemented in a manner as seen here:

https://github.com/bryceac/BCheckbook/blob/main/Shared/Models/BCheckFileDocument.swift#L70-L89

I then made a property on the observable object that would specify the content type, so that fileExporter() only needed to be present once and then all you need is something like this in the main view to set the content type.

https://github.com/bryceac/BCheckbook/blob/main/iOS/Views/ContentView.swift#L72-L84

1      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.