The following results in a crash:
swift
import Combine
let subject = PassthroughSubjectString, Error()
let cancellable = subject.map { _ in
EmptyString?, Error().replaceError(with: nil)
}
.switchToLatest()
.sink {
print($0)
} receiveValue: {
print($0 ?? "none")
}
subject.send("") // EXC_BAD_INSTRUCTION
Am I doing something wrong, or is this a bug? Filed as FB9042788.
Post
Replies
Boosts
Views
Activity
I'd like to emulate the behavior of UIViewController.isModalInPresentation in SwiftUI. In my first attempt, I defined the following view:
struct ModalView<Content: View>: UIViewControllerRepresentable {
		var content: () -> Content
		func makeUIViewController(context: Context) -> UIHostingController<Content> {
				let controller = UIHostingController(rootView: content())
				controller.isModalInPresentation = true
				return controller
		}
		func updateUIViewController(_ imagePickerController: UIHostingController<Content>, context: Context) {}
}
From my main app view, I then present the ModalView as a sheet:
struct ContentView: View {
		@State
		var presentSheet: Bool = true
		var body: some View {
				Text("Hello, world!")
						.sheet(isPresented: $presentSheet) {
								ModalView {
										Text("Sheet")
								}
						}
		}
}
But the user is still able to dismiss the ModalView by swiping down. I would expect this sheet to be non-dismissible. Is anything like this supposed to work? If not, is there some other way to prevent the dismissal of a sheet in SwiftUI?
The closest workaround I've found is to apply .highPriorityGesture(DragGesture()) to the content of the sheet, but swiping down with two fingers still works.