Post

Replies

Boosts

Views

Activity

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
344
Nov ’24
SwiftuI view Error
Hi Im copying the Apple tutorial project for lists and navigation for SWiftUI but Im getting an error although my code is same as Apple project, can some one check please. Error "Cannot find 'landmarks' in scope" Kindest Regards import SwiftUI struct LandmarkRow: View {     var landmark: Landmark     var body: some View {         HStack {             Text(landmark.name)         }     } } struct LandmarkRow_Previews: PreviewProvider {     static var previews: some View {         LandmarkRow(landmark: landmarks[0])     } } import Foundation import SwiftUI import CoreLocation struct Landmark: Hashable, Codable {     var id: Int     var name: String     var park: String     var state: String     var description: String          private var imageName: String     var image: Image {         Image(imageName)     }          private var coordinates: Coordinates          var locationCoordinate: CLLocationCoordinate2D {         CLLocationCoordinate2D (             latitude: coordinates.latitude,             longitude: coordinates.longitude)     }          struct Coordinates: Hashable, Codable {         var latitude: Double         var longitude: Double     }      }
2
0
1k
Oct ’21
Adding multi view to NavigationPath in one go
Hi How can we add multi view to NavigationPath in one go like in code below maybe using something like path.append(mobiles.all) ? where all 3 views of mobiles Array get added at once ? Kindest Regards `struct NavigationPathView: View { var mobiles: [Mobiles] = [.init (name: "iPhone", imageName: "folder", color: .mint), .init (name: "Samsung", imageName: "pin", color: .pink), .init (name: "Mac Pro", imageName: "book", color: .gray)] @State var path = NavigationPath() var body: some View { NavigationStack (path: $path) { List { Section ("Platforms") { Button("Go To Platform") { path.append(mobiles.first!) } Button("Go To Mobile") { path.append(mobiles.last!) } Button("Add All Mobiles") { } } } } .navigationDestination(for: Mobiles.self) {mobile in ZStack { mobile.color.ignoresSafeArea() VStack { Image(systemName: mobile.imageName) Label (mobile.name, systemImage: mobile.imageName) .font(.largeTitle).bold().foregroundColor(.white) Button("Go Home") { path.removeLast(path.count) } } } } } }
2
0
526
Jun ’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)) } }
Topic: UI Frameworks SubTopic: SwiftUI
2
0
457
Sep ’24
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
475
Nov ’24
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
Topic: UI Frameworks SubTopic: SwiftUI
2
0
502
Nov ’24