Post

Replies

Boosts

Views

Activity

Customizing Tables in SwiftUI
Hi, How to customize tables in SwiftUI its color background for example, the background modifier doesn't work ? how to change separator lines ? rows background colors ? give header row different colors to its text and background color ? Kind Regards
1
0
75
4d
SwiftData Master Details
I want to create master details relationship between patient and vitals signs so which of option codes below are better performance wise ? Option one is master - details done manually .. option 1 @Model class TestResult { @Attribute(.primaryKey) var id: UUID var patientID: UUID Option 2 @Model final class Vital { var patient: Patient?
0
0
110
1w
Modifying SwiftData Object
Hi, The dataModule in code below is a swiftData object being passed to the view and its property as key path but when trying to modify it I'm getting the error ."Cannot assign through subscript: 'self' is immutable" how to solve this issue ? Kind Regards struct ListSel<T: PersistentModel>: View { @Bindable var dataModule: T @Binding var txtValue: String var keyPath: WritableKeyPath<T, String> var turncate: CGFloat? = 94.0 var image = "" var body: some View { HStack { Text(txtValue) .foregroundColor(sysSecondary) .font(.subheadline) .onChange(of: txtValue) { value in dataModule[keyPath: keyPath] = value } Image(systemName: image) .foregroundColor(sysSecondary) .font(.subheadline) .imageScale(.small) .symbolRenderingMode(.hierarchical) .scaleEffect(0.8) } .frame(width: turncate, height: 20, alignment: .leading) .truncationMode(.tail) } }
2
0
168
2w
Using Generic SwiftData Modules
Hi, I have the view below that I want it to get any sort of SwiftData model and display and string property of that module, but I get the error mentioned below as well, also the preview have an error as below, how to fix it ? I know its little complicated. Error for the view GWidget " 'init(wrappedValue:)' is unavailable: The wrapped value must be an object that conforms to Observable " Error of preview " Cannot use explicit 'return' statement in the body of result builder 'ViewBuilder' " 3, Code #Preview { do { let configuration = ModelConfiguration(isStoredInMemoryOnly: true) let container = try ModelContainer(for: Patient.self, configurations: configuration) let example = Patient(firstName: "Ammar S. Mitoori", mobileNumber: "+974 5515 7818", homePhone: "+974 5515 7818", email: "ammar.s.mitoori@gmail.com", bloodType: "O+") // Pass the model (Patient) and the keyPath to the bloodType property return GWidget(model: example, keyPath: \Patient.bloodType) .modelContainer(container) } catch { fatalError("Fatal Error") } } 4. Code for the Gwidget View ```import SwiftUI import SwiftData struct GWidget<T>: View { @Bindable var model: T var keyPath: KeyPath<T, String> // Key path to any string property // Variables for the modified string and the last character var bloodTypeWithoutLast: String { let bloodType = model[keyPath: keyPath] return String(bloodType.dropLast()) } var lastCharacter: String { let bloodType = model[keyPath: keyPath] return String(bloodType.suffix(1)) } var body: some View { VStack(alignment: .leading) { Text("Blood Type") .font(.footnote) .foregroundStyle(sysPrimery07) HStack (alignment: .lastTextBaseline) { Text(bloodTypeWithoutLast) .fontWeight(.bold) .font(.title2) .foregroundStyle(sysPrimery07) VStack(alignment: .leading, spacing: -5) { Text(lastCharacter) .fontWeight(.bold) Text(lastCharacter == "+" ? "Positive" : "Negative") } .font(.caption2) .foregroundStyle(lastCharacter == "+" ? .green : .pink) } } } }
3
0
230
Oct ’24
SwifttData Record Update
Hi When connecting a SwiftData module property to a SwiftUI view such as a text field and the field changes by user the property get updated in the SwiftData database, now suppose I want to run a validation code or delay updates to Database till use click a submit button how to do that ? delay those auto updates if we can name it ? Kind Regards Code Example import SwiftUI import SwiftData struct GListSel2: View { @Bindable var patient: Patient var body: some View { HStack { TextField("Gender", text: $patient.gender) } } }
1
0
118
2w
SwipeAction in For Each
Hi, Im trying to use ForEach without list to get rid of the navigation chevron , but the sipe to delete modifier stop working, is there a some solution ? Kind Regards Button(role: .destructive) { deletePatient(patient: patient) } label: { VStack { Label("Delete", systemImage: "trash") Image(systemName: "Trash") } } }
3
0
149
Oct ’24
Split View DoubleColumn Mode
Hi, When SplitView is in detailsOnly and I swipe from left side the sidebar appears as popover above the details content, but when I try to open it manually by settings the columnVisibility to doubleColumn it pushes the details view and shows, so haw to make it appear as poorer ? Kind Regards
0
0
104
Oct ’24
Customizing Tab | Side Bars
Hi, The new TabBar, SideBar combination is very nice, but I tried customizing like text sizes, icon sizes using imageScale and all dint have any effect, also shows of selected item in side bar couldn't customize it, is there any suggestions ? Kind Regards
0
0
141
Sep ’24
Reducing space between list rows
Hi, However I tried to reduce space between list rows in below code I fail, is there any way to reduce this space ? @State var flag: Bool = false var myList: [String] = ["Hello", "World", "SwiftUI"] var body: some View { VStack(alignment: .leading) { List (myList, id: \.self) { list in Text(list) .border(Color.black) .font(.system(size: 12)) // Smaller font size .frame(maxWidth: .infinity, minHeight: 20, alignment: .leading) // Reduced height .padding(.vertical, 4) // Minimal padding for vertical spacing .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) // Remove insets .listRowSeparator(.hidden) // Hide separator } .listStyle(.plain) } .overlay( RoundedRectangle(cornerRadius: 10) .stroke(sysSecondary.opacity(0.4), lineWidth: 1) ) .frame(width: 220, height:260) .background(.white) .clipShape (RoundedRectangle (cornerRadius: 10)) } }
2
0
182
Sep ’24