Type of expression is ambiguous without context error fix needed

Im getting the errror on the line where it says @Environment. The error is highliting the exportFiles part on that line. Any ideas anyone? A fix will be highly appreciated
Thanks in advance

Code Block import SwiftUI
import PlaygroundSupport
struct ContentView: View {
    @Environment(\.exportFiles) var exportAction
    
    var body: some View {
        Button("Export Your file") {
            let url = Bundle.main.url(forResource: "symbols",
                                      withExtension: "json")!
            exportAction(moving: url)  {result in
                switch result {
                    case .success(let url):
                    print("Success! Moved to: /url")
                }
            }
        }
    }
    
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
PlaygroundPage.current.setLiveView(ContentView())


I cannot reproduce the same error on the line you specified.
But I get another error saying Switch must be exhaustive.
  • Are you sure you are running your code on Xcode 12 beta?

  • What happens if you fixed other errors:

Code Block
import PlaygroundSupport
import SwiftUI
struct ContentView: View {
    @Environment(\.exportFiles) var exportAction
    var body: some View {
        Button("Export Your file") {
            let url = Bundle.main.url(forResource: "symbols",
                                      withExtension: "json")!
            exportAction(moving: url)  {result in
                switch result {
                case .success(let url):
                    print("Success! Moved to: \(url)")
                case .failure(let error):
                    print(error)
                case .none:
                    print("Export was cancelled")
                }
            }
        }
    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
PlaygroundPage.current.setLiveView(ContentView())

Are you building for iOS 14 ?
Which line is highlighted ?
Note: when you paste code in Forum, use 'Paste and match style', to avoid the many extra blank lines.

Code Block
import PlaygroundSupport
struct ContentView: View {
@Environment(\.exportFiles) var exportAction
var body: some View {
Button("Export Your file") {
let url = Bundle.main.url(forResource: "symbols",
withExtension: "json")!
exportAction(moving: url) {result in
switch result {
case .success(let url):
print("Success! Moved to: /url")
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
PlaygroundPage.current.setLiveView(ContentView())

You're using APIs from the iOS 14 beta that were replaced in the final release. That's why the environment value doesn't exist.

From the iOS 14 release notes:

The ImportFilesAction and ExportFilesAction APIs have been replaced
with a collection of new view modifiers.

Use the new .fileImporter() modifier to present a system interface for
importing one or more files into your app, and the new .fileMover()
modifier to move one or more existing files to a new location. The
following is an example of a simple UI for importing and moving files:

Use the new .fileExporter() modifier to present a system interface for
exporting one or more documents from your app. In this example, an app
provides a simple note-taking interface for quickly jotting down some
text and then exporting it to disk:

Code Block swift
struct QuickNote : View {
@Binding var draft: QuickNoteDocument
@State private var isExporting: Bool = false
var body: some View {
TextEditor(text: $draft.text)
.toolbar {
Button("Save", action: { isExporting = true })
}
.fileExporter(
isPresented: $isExporting,
document: draft,
contentType: .plainText,
defaultFilename: "MyNote"
) { result in
// Clear the draft now that it's saved.
if case .success = result {
draft.text = ""
} else {
// Handle failure.
}
}
}
}
struct QuickNoteDocument : FileDocument {
static var readableContentTypes: [UTType] { [.plainText] }
var text: String
init(text: String) {
self.text = text
}
init(configuration: ReadConfiguration) throws {
// Deserialize the document.
}
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
// Serialize the document.
}
}




Type of expression is ambiguous without context error fix needed
 
 
Q