In my app I used locationButton and everything worked fine. Then I added Localizable string file and localized for English. Still, everything worked OK. Then I added localized String file for Hebrew, and it compiles, opens my simulator and shows everything in Hebrew But then I try to use the app and click something and it crashes and gives me this error: Thread 1: "Invalid parameter not satisfying: width && height". Can't find anything about this anywhere. Did anyone encountered this?
why app crashes when I use localization and LocationButton in swiftui? I get this error:Thread 1: "Invalid parameter not satisfying: width && height"
Would you provide a sample code?
Very hard to say without any code.
- Do you try to set locationButton Title ?
- Have you set any constraints ?
May be some hint here:
https://developer.apple.com/forums/thread/36745
Sounds like you're passing .infinity
to a width and height parameter of a frame. it might be best to use a GeometryReady to get a width & height as the minWidth & minHeight and use .infinity
as the maxWidth & maxHeight or just use an absolute w x h.
Hey guys, this is my code:
import SwiftUI
import MapKit
import CoreLocationUI
struct ContentView: View {
@StateObject var vm = ViewModel()
var body: some View {
VStack {
Text("location")
LocationButton(.currentLocation) { vm.reqestUserLocationOnce() }
.foregroundColor(.white)
.symbolVariant(.fill)
.labelStyle(.iconOnly)
.clipShape(Capsule())
}
}
}
class ViewModel: NSObject, ObservableObject, CLLocationManagerDelegate {
private let locationManager = CLLocationManager()
override init() {
super.init()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
}
func reqestUserLocationOnce() { locationManager.requestLocation() }
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let currenLocation = locations.last else { return }
CLGeocoder().reverseGeocodeLocation(currenLocation) { placemarks, error in
guard error == nil else { return }
guard let placemark = placemarks?.first else { return }
guard placemark.location?.coordinate != nil else { return }
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { print(error.localizedDescription) }
}
And then I have 2 String Files in English and Hebrew:
English:
/*
Localizable.strings
*/
"location" = "Location:";
Hebrew:
"location" = "מיקום:";
So, if you make a project with my code and the String file in English, everything works fine. But then try to add the Hebrew String file snd see how it crashes. Bummer. Does anyone know why? Is it a swift or Xcode bug? I have no Idea.