I am an android developer for 6+ years but recently I started doing iOS. I picked up SwiftUI which I think it's amazing and I built some screens.
However, I am getting this error in the log and when clicking on a TextField the first time. When I do that the screen is going back to the previous screen (I am going to this screen from a navigationLink)
The error I encounter is this:
2021-01-10 12:52:58.682264+0200 appName[2025:1085202] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x280e898b0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x11d57ed20]-(6)-[_UIModernBarButton:0x11d57e3e0'Add Point'] (active)>",
"<NSLayoutConstraint:0x280e89900 'CB_Trailing_Trailing' _UIModernBarButton:0x11d57e3e0'Add Point'.trailing <= _UIButtonBarButton:0x11d57e010.trailing (active)>",
"<NSLayoutConstraint:0x280e8a440 'UINav_static_button_horiz_position' _UIModernBarButton:0x11d57ed20.leading == UILayoutGuide:0x28143ed80'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x280e8a490 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x11d57e010]-(0)-[UILayoutGuide:0x28143eca0'UINavigationBarItemContentLayoutGuide'] (active)>",
"<NSLayoutConstraint:0x280e436b0 'UINavItemContentGuide-trailing' UILayoutGuide:0x28143eca0'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x11d543390.trailing (active)>",
"<NSLayoutConstraint:0x280e8ab70 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x11d543390.width == 0 (active)>",
"<NSLayoutConstraint:0x280e43d40 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x28143ed80'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UINavigationBarContentView:0x11d543390 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x280e898b0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x11d57ed20]-(6)-[_UIModernBarButton:0x11d57e3e0'Add Point'] (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
And my view is this one:
import SwiftUI
struct AddEvent: View {
var body: some View {
NavigationView {
VStack {
TextField("Title", text: $title)
.font(Font.system(size: 16, weight: .bold, design: .serif))
.padding(10)
.overlay(RoundedRectangle(cornerRadius: 10).stroke(Color("AccentColor"), lineWidth: 1))
TextEditor(text: $details)
.font(Font.system(size: 15, weight: .bold, design: .serif))
.overlay(RoundedRectangle(cornerRadius: 10).stroke(Color("AccentColor"), lineWidth: 1))
.frame(maxWidth: .infinity, minHeight: 100, maxHeight: 150, alignment: .top)
DatePicker("Date and time", selection: $dateTime)
.padding()
Button(action: {
self.showingDetail.toggle()
}) {
Text("Pick coordonates")
}.sheet(isPresented: $showingDetail) {
Capsule()
.fill(Color.secondary)
.frame(width: 60, height: 4)
.padding(16)
AdminMapsView(isLongClickEnabled: true, hideLocationButton: false, latitude: self.$latitude, longitude: self.$longitude)
.padding(.top, 32)
}
.padding()
Button(action: {
if self.latitude > 0.0 && self.longitude > 0.0 && !self.titlu.isEmpty && !self.detaliu.isEmpty {
databaseService.addEvent(title: self.titlu, details: self.detaliu, date: self.dateTime, lat: self.latitude, long: self.longitude)
self.showingAlert = true
self.titlu = ""
self.detaliu = ""
} else {
self.mandatory = true
}
}) {
Text("Add event")
.frame(maxWidth: .infinity)
.padding(10.0)
.overlay(
RoundedRectangle(cornerRadius: 10.0)
.stroke(lineWidth: 2.0)
)
}.padding(.top, 15)
.alert(isPresented: $showingAlert) {
Alert(title: Text("Felicitări"), message: Text("Mesajul a fost adăugat cu succes."), dismissButton: .default(Text("Închidere")))
}
.alert(isPresented: $mandatory) {
Alert(title: Text("Atenție"), message: Text("Toate campurile trebuie sa fie completate."), dismissButton: .default(Text("Închidere")))
}
Spacer()
}
.navigationBarTitle("Add Point")
.navigationBarHidden(true)
.padding()
}
}
}
struct AddEvent_Previews: PreviewProvider {
static var previews: some View {
AddEvent()
}
}
I removed some variables so the code will be less and easier to understand.
I find it very hard to debug that log, if anyone can give me some hints, I think the apple developer documentation is very ambiguous and hard to follow. Thanks!