The problem cropped up again, and I bit the bullet. In Xcode, I created a new project and copied all the source from the old to the new project. I recreated everything in the new project, meaning: set the bundle ID, version number, build number, launch screen et cetera.
That fixed it. So, it's not the source files themselves, it's something in the project file(s). I did a manual diff between the <projectname>.xcodeproj/project.pbxproj of the old and the new project, but I gave up after staring 15 minutes at the incredibly messy diff. Preview now work.
After upgrading to Xcode 12.2 beta 3 (12B5035g), one failing preview offered an error: a unittest (i.e. an XCTestCase subclass) was not part of any target. Of course, it was part of the unittest target only. So I have no idea why the preview depended on that unittest file. I just deleted the file from Xcode, and for this project, the error "Failed to build ***.swift" keeps popping up above the preview but if I repeatedly hit Cmd-Shift-P, it does render.
Edit: never mind, other views no longer render. Very frustrating.
Once, I found that the project had multiple targets. And the file wasn't a member of the currently selected target. But that only happened once. Other times, I found that repeatedly clicking the preview button (or repeatedly pressing Option-Cmd-P) fixed it. But most of the time, the preview is simply not appearing.
Xcode 12.0 and 12.2 series are rough for me, right now.
There are multiple ways to go about this, but I like the approach of a State variable named "action" into your SwiftUI view, and via that variable, you update the map type.
The following project has a number of examples of using UIKit stuff in your SwiftUI project. I already had a MapKit example, and have updated it to allow changing the map type:
GitHub - https://github.com/bvankuik/UIViewRepresentableExamples
The code in question:
import SwiftUI
import CoreLocation
import MapKit
extension CLLocationCoordinate2D {
		var description: String {
				String(format: "%.8f, %.8f", self.latitude, self.longitude)
		}
}
extension MapKitExample {
		struct PickerValues {
				let mapType: MKMapType
				let description: String
		}
}
struct MapKitExample: View {
		static let amsterdam = CLLocationCoordinate2D(latitude: 52.37403,
																									longitude: 4.88969)
		@State private var centerCoordinate = Self.amsterdam
		@State private var action: MapView.Action = .idle
		@State private var mapPickerSelection: Int = 0
		let pickerValues: [PickerValues] = [// [.standard, .hybrid, .satellite]
				PickerValues(mapType: .standard, description: "Standard"),
				PickerValues(mapType: .hybrid, description: "Hybrid"),
				PickerValues(mapType: .satellite, description: "Satellite"),
		]
		var body: some View {
				let binding = Binding<Int>(
						get: { self.mapPickerSelection},
						set: { newValue in
								self.action = .changeType(mapType: self.pickerValues[newValue].mapType)
								self.mapPickerSelection = newValue
						}
				)
				return VStack {
						MapView(centerCoordinate: self.$centerCoordinate, action: self.$action)
						Picker(selection: binding, label: Text("Map type")) {
								ForEach(self.pickerValues.indices) { index in
										Text(self.pickerValues[index].description).tag(index)
								}
						}.pickerStyle(SegmentedPickerStyle())
						Text("Centered on: " + self.centerCoordinate.description)
						Button("Reset") {
								self.action = .reset(coordinate: Self.amsterdam)
						}
				}
				.navigationBarTitle("MapKit Example")
		}
}
struct MapView: UIViewRepresentable {
		enum Action {
				case idle
				case reset(coordinate: CLLocationCoordinate2D)
				case changeType(mapType: MKMapType)
		}
		@Binding var centerCoordinate: CLLocationCoordinate2D
		@Binding var action: Action
		func makeUIView(context: Context) -> MKMapView {
				let mapView = MKMapView()
				mapView.delegate = context.coordinator
				mapView.centerCoordinate = self.centerCoordinate
				return mapView
		}
		func updateUIView(_ uiView: MKMapView, context: Context) {
				switch action {
				case .idle:
						break
				case .reset(let newCoordinate):
						uiView.delegate = nil
						uiView.centerCoordinate = newCoordinate
						DispatchQueue.main.async {
								self.centerCoordinate = newCoordinate
								self.action = .idle
								uiView.delegate = context.coordinator
						}
				case .changeType(let mapType):
						uiView.mapType = mapType
				}
		}
		func makeCoordinator() -> Coordinator {
				Coordinator(self)
		}
		class Coordinator: NSObject, MKMapViewDelegate {
				var parent: MapView
				func mapViewDidChangeVisibleRegion(_ mapView: MKMapView) {
						parent.centerCoordinate = mapView.centerCoordinate
				}
				init(_ parent: MapView) {
						self.parent = parent
				}
		}
}
Post not yet marked as solved
You're going to get more answers if you dump the Core Data stuff and just add some data via constants.
Thanks, that was it. Much appreciated.