Good morning,
In using “equivalent” code for two lists I obtain an error for a constraint for one of the lists
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.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x6000021aaa80 h=-&- v=--& SwiftUI.UIKitNavigationBar:0x1030af090.minY == 0 (active, names: '|':UILayoutContainerView:0x1030b0d60 )>",
"<NSAutoresizingMaskLayoutConstraint:0x6000021aae90 h=-&- v=--& SwiftUI.UIKitNavigationBar:0x1030af090.height == 108 (active)>",
"<NSLayoutConstraint:0x60000219f4d0 V:[SwiftUI.UIKitNavigationBar:0x1030af090]-(0)-[UIFocusContainerGuide:0x600003d0eb20'UINavigationControllerContentFocusContainerGuide'] (active)>",
"<NSLayoutConstraint:0x60000219f5c0 UIFocusContainerGuide:0x600003d0eb20'UINavigationControllerContentFocusContainerGuide'.bottom == UILayoutContainerView:0x1030b0d60.bottom (active)>",
"<NSLayoutConstraint:0x6000021b9db0 'UIView-Encapsulated-Layout-Height' UILayoutContainerView:0x1030b0d60.height == 36 (active)>"
)
Any suggestions as to decipher the error message and identify which constraint is being referred to. The code for the lists is provided as well as the screen
Instrument list - works
type or import SwiftUI
import SwiftData
struct PouchInstrumentList: View {
@Environment(\.modelContext) private var context
var pouch: Pouches
@Query var instruments: [Instrument]
@State private var multiSelection = Set<String>()
@State private var selectedInstruments = [Instrument]()
var body: some View {
NavigationStack {
VStack {
List (instruments, selection: $multiSelection) { instrument in
HStack {
Text(instrument.catagory)
.frame (
maxWidth: .infinity,
maxHeight: .infinity,
alignment: .leading
)
Text(instrument.name)
.frame (
maxWidth: .infinity,
maxHeight: .infinity,
alignment: .leading
)
}
}
.listStyle(.plain)
.toolbar {
ToolbarItem(placement: .navigationBarLeading){
if !selectedInstruments.isEmpty {
Button {
selectedInstruments.removeAll()
} label: {
Image(systemName: "trash")
.backgroundStyle(.red)
}
}
}
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
}
Text("\(multiSelection.count) selected")
.onChange( of: multiSelection) { oldValue , newValue in// new value contains id of selected instruments
for value in newValue { //loop thru selected values
let selectedInstrument = instruments.first(where: { $0.id == value }) // unwrap optional
if let selectedInstrument {
if !selectedInstruments.contains(selectedInstrument) { // if instrument is not in selected list
selectedInstruments.append(selectedInstrument) // add to list
}
}
}
}
}
}
}
}
KitList
import SwiftUI
import SwiftData
struct PouchKitList: View {
@Environment(\.modelContext) private var context
var kit: Kits
@Query var kits: [Kits]
@State private var multiSelection = Set<String>()
@State private var selectedKits = [Kits]()
var body: some View {
NavigationStack {
VStack {
List (kits, selection: $multiSelection) { kit in
HStack {
Text(kit.name)
.frame (
maxWidth: .infinity,
maxHeight: .infinity,
alignment: .leading
)
}
}
.listStyle(.plain)
.toolbar {
ToolbarItem(placement: .navigationBarLeading){
if !selectedKits.isEmpty {
Button {
selectedKits.removeAll()
} label: {
Image(systemName: "trash")
.backgroundStyle(.red)
}
}
}
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
}
Text("\(multiSelection.count) selected")
.onChange( of: multiSelection) { oldValue , newValue in// new value contains id of selected instruments
for value in newValue { //loop thru selected values
let selectedKit = kits.first(where: { $0.name == value }) // unwrap optional
if let selectedKit {
if !selectedKits.contains(selectedKit) { // if kit is not in selected list
selectedKits.append(selectedKit) // add to list
}
}
}
}
}
}
}
}

Thanks
Joel