Hey there,
I am currently developing a SwiftUI app for iPad.
However, I am currently experiencing a behavior, that I can not explain.
My code creates a user-management view. This all works fine if I run it on my iPad Pro with Apple-M-Chip. However, if I try to run the exact same code on an older A-Chip iPad Air (4th Generation), my app crashes.
I can recreate this behavior in the simulator on my Mac. When I run it on an iPad Pro Simulator, all works fine. When I run it in an iPad Air (4th Gen) simulator, the app becomes unresponsive.
Unfortunatley Xcode does not throw any error that I could use to identify the problem.
Currently I solved it with a work-around: As soon as I add a Spacer (even with a with of 0) the code works as expected and the UI is shown. As soon as I remove the Spacer, it crashes again.
HStack(alignment: .top){
VStack{
if(data.ui_user.id != -1){
HStack{
Text("Employee-No.:")
Spacer()
TextField("Employee-No.", value: $data.ui_user.id, format: .number).textFieldStyle(.roundedBorder).disabled(true).containerRelativeFrame(.horizontal, count: 10, span: 3, spacing: 0)
}
}
HStack{
Text("Family Name:")
Spacer()
TextField("Family Name", text: $data.ui_user.familyName).textFieldStyle(.roundedBorder).containerRelativeFrame(.horizontal, count: 10, span: 3, spacing: 0)
}
HStack{
Text("Given Name:")
Spacer()
TextField("Given Name", text: $data.ui_user.givenName).textFieldStyle(.roundedBorder).containerRelativeFrame(.horizontal, count: 10, span: 3, spacing: 0)
}
HStack{
Text("Role:")
Spacer()
Picker("Select role", selection: $data.selectedRole){
ForEach(0 ..< self.availableRoles.count, id:\.self){
Text(self.availableRoles[$0].name ?? "???").tag($0)
}
}.pickerStyle(.menu).containerRelativeFrame(.horizontal, count: 10, span: 3, spacing: 0).background(.drkBlueContainer).cornerRadius(5).foregroundColor(.drkOnBlueContainer).tint(.drkOnBlueContainer)
//If I add this spacer, it works. If not, it crashes
//Spacer().frame(width: 0.0)
}.disabled(noEditAdmin && data.ui_user.id != -1)
}
Divider()
VStack{
HStack{
Text("Created at:")
Spacer()
TextField("Created at", value: $data.ui_user.createdAt, format: .dateTime).textFieldStyle(.roundedBorder).disabled(true).containerRelativeFrame(.horizontal, count: 10, span: 3, spacing: 0)
}
HStack{
Toggle("Terminates:", isOn: $data.ui_user.expires)
.padding(.trailing, 2.0)
}
if(data.ui_user.expires){
HStack{
DatePicker("Terminates at:", selection: $data.ui_user.expiresAt, displayedComponents: .date).pickerStyle(.automatic)
}}
}
}
If anyone has any ideas, I would be very grateful for a hint :-)