Unfortunately, I have the same issue in Version 14.0 (14A309) (release version).
I've thought out another workaround. It may not be acceptable for some scenarios but in other it may be bearable. Below is the example of 2 ObservableObject classes --> Object1 produces the error, Object2 does not.
class Object1: ObservableObject {
@Published var title = ""
func setTitle(to newTitle: String) {
title = newTitle // this causes the error in question ("Publishing changes from within view updates is not allowed, this will cause undefined behavior.")
}
}
class Object2: ObservableObject {
@Published var title = ""
func setTitle(to newTitle: String) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { // performing the change later on removes the error because obviously it is not "within view updates"
self.title = newTitle
}
}
}
Post
Replies
Boosts
Views
Activity
To solve this error:
Instance method 'onChange(of:perform:)' requires that 'MKCoordinateRegion' conform to 'Equatable'
you need to do conform 'MKCoordinateRegion' to 'Equatable' as it the error suggests. You can do it like eg. this:
import MapKit
extension MKCoordinateRegion: Equatable {
public static func == (lhs: MKCoordinateRegion, rhs: MKCoordinateRegion) -> Bool {
if lhs.center.latitude == rhs.center.latitude && lhs.span.latitudeDelta == rhs.span.latitudeDelta && lhs.span.longitudeDelta == rhs.span.longitudeDelta {
return true
} else {
return false
}
}
}