Post

Replies

Boosts

Views

Activity

Reply to One to Many Relationship in SwiftData
I tried the code below, with SiftData models also below, but I got the error .. Value of type Sight has no member destination ! ForEach (destination.sights) { sight in VStack { Text(sight.name) Text(sight.destination.name) } } @Model class Destination { var name: String var details: String var date: Date var priority: Int @Relationship(deleteRule: .cascade) var sights = [Sight]() init(name: String = "", details: String = "", date: Date = .now, priority: Int = 2) { self.name = name self.details = details self.date = date self.priority = priority } } @Model class Sight { var name: String init(name: String) { self.name = name } }
Sep ’24
Reply to SwipeAction in For Each
Hello @Claude31 , thanks for the replay, below is the full code .. import SwiftUI import SwiftData struct PatientsList: View { @Environment(\.modelContext) var modelContext @Query(sort: [SortDescriptor(\Patient.firstName), SortDescriptor(\Patient.birthday)]) var patients: [Patient] var body: some View { List { ForEach(patients) { patient in HStack { NavigationLink (value: patient) { PatientRow(patient: patient) } } .alignmentGuide(.listRowSeparatorLeading) { _ in -50 } .listRowSeparatorTint(sysSecondary02) .swipeActions(edge: .trailing) { Button(role: .destructive) { deletePatient(patient: patient) } label: { VStack { Label("Delete", systemImage: "trash") Image(systemName: "Trash") } } } } } .scrollIndicators(.hidden) .foregroundStyle(sysSecondary08) .listStyle(.plain) } func deletePatient(patient: Patient) { modelContext.delete(patient) } init(sort: SortDescriptor<Patient>, searchString: String) { _patients = Query(filter: #Predicate { if searchString.isEmpty { return true } else { return $0.firstName.localizedStandardContains(searchString) } }, sort: [sort]) } } #Preview { PatientsList(sort: SortDescriptor(\Patient.firstName), searchString: "") }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’24
Reply to Using Generic SwiftData Modules
Ok now the solution you suggested raised few more questions and errors as below .. Now to use the T with text such as Text(T.age) it will complain that T doesn't have no age property ? Now suppose I want even the property of the T to be also generic and passed to the view as argument how we do it like T.T ? can I see an example ? Im trying to make a generic view that shows any property of any SwiftData module. Also #Preview is compiling that the generic variable isn't initialized and I wonder how can we initialize a generic variable ? I get the error .. Missing argument for parameter 'dataModule' in call import SwiftUI import SwiftData struct GenderList2<T: PersistentModel>: View { @Bindable var dataModule: T var body: some View { HStack(alignment: .top) { Text(T.age) } } } #Preview { GenderList2() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’24
Reply to Using Generic SwiftData Modules
@DTS Engineer I think the code below works, ill keep testing and update you, import SwiftUI import SwiftData struct SwiftUIView<T: PersistentModel>: View { @Bindable var dataModule: T var keyPath: KeyPath<T, String> var body: some View { HStack(alignment: .top) { Text(dataModule[keyPath: keyPath]) } } } #Preview { do { let configuration = ModelConfiguration(isStoredInMemoryOnly: true) let container = try ModelContainer(for: Patient.self, configurations: configuration) let example = Patient(firstName: "First Name", mobileNumber: "+974 1234 5678", homePhone: "+974 1234 5678", email: "firstname.lastname@gmail.com") return SwiftUIView(dataModule: example, keyPath: \.firstName) .modelContainer(container) } catch { fatalError("Fatal Error") } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’24
Reply to Sorting SwiftData module records based on recent update
Thanks allot, so is there any API or observation method to get notified when some record is changed or that should be done manually as well ? Kind Regards
Replies
Boosts
Views
Activity
Aug ’24
Reply to One to Many Relationship in SwiftData
I tried the code below, with SiftData models also below, but I got the error .. Value of type Sight has no member destination ! ForEach (destination.sights) { sight in VStack { Text(sight.name) Text(sight.destination.name) } } @Model class Destination { var name: String var details: String var date: Date var priority: Int @Relationship(deleteRule: .cascade) var sights = [Sight]() init(name: String = "", details: String = "", date: Date = .now, priority: Int = 2) { self.name = name self.details = details self.date = date self.priority = priority } } @Model class Sight { var name: String init(name: String) { self.name = name } }
Replies
Boosts
Views
Activity
Sep ’24
Reply to One to Many Relationship in SwiftData
@joadan Aha you mean we should explicitly add Destination to Sight in above code ? it won't be implicitly implemented ? that way yes it worked.
Replies
Boosts
Views
Activity
Sep ’24
Reply to SwipeAction in For Each
Hello @Claude31 , thanks for the replay, below is the full code .. import SwiftUI import SwiftData struct PatientsList: View { @Environment(\.modelContext) var modelContext @Query(sort: [SortDescriptor(\Patient.firstName), SortDescriptor(\Patient.birthday)]) var patients: [Patient] var body: some View { List { ForEach(patients) { patient in HStack { NavigationLink (value: patient) { PatientRow(patient: patient) } } .alignmentGuide(.listRowSeparatorLeading) { _ in -50 } .listRowSeparatorTint(sysSecondary02) .swipeActions(edge: .trailing) { Button(role: .destructive) { deletePatient(patient: patient) } label: { VStack { Label("Delete", systemImage: "trash") Image(systemName: "Trash") } } } } } .scrollIndicators(.hidden) .foregroundStyle(sysSecondary08) .listStyle(.plain) } func deletePatient(patient: Patient) { modelContext.delete(patient) } init(sort: SortDescriptor<Patient>, searchString: String) { _patients = Query(filter: #Predicate { if searchString.isEmpty { return true } else { return $0.firstName.localizedStandardContains(searchString) } }, sort: [sort]) } } #Preview { PatientsList(sort: SortDescriptor(\Patient.firstName), searchString: "") }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’24
Reply to Using Generic SwiftData Modules
Ok now the solution you suggested raised few more questions and errors as below .. Now to use the T with text such as Text(T.age) it will complain that T doesn't have no age property ? Now suppose I want even the property of the T to be also generic and passed to the view as argument how we do it like T.T ? can I see an example ? Im trying to make a generic view that shows any property of any SwiftData module. Also #Preview is compiling that the generic variable isn't initialized and I wonder how can we initialize a generic variable ? I get the error .. Missing argument for parameter 'dataModule' in call import SwiftUI import SwiftData struct GenderList2<T: PersistentModel>: View { @Bindable var dataModule: T var body: some View { HStack(alignment: .top) { Text(T.age) } } } #Preview { GenderList2() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’24
Reply to Using Generic SwiftData Modules
@DTS Engineer I think the code below works, ill keep testing and update you, import SwiftUI import SwiftData struct SwiftUIView<T: PersistentModel>: View { @Bindable var dataModule: T var keyPath: KeyPath<T, String> var body: some View { HStack(alignment: .top) { Text(dataModule[keyPath: keyPath]) } } } #Preview { do { let configuration = ModelConfiguration(isStoredInMemoryOnly: true) let container = try ModelContainer(for: Patient.self, configurations: configuration) let example = Patient(firstName: "First Name", mobileNumber: "+974 1234 5678", homePhone: "+974 1234 5678", email: "firstname.lastname@gmail.com") return SwiftUIView(dataModule: example, keyPath: \.firstName) .modelContainer(container) } catch { fatalError("Fatal Error") } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’24
Reply to Modifying SwiftData Object
@Fat Xu Thanks allot that solved the problem
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’24
Reply to Customizing Tables in SwiftUI
Thanks allot, its for iOS but ill check the link thanks allot.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Nov ’24
Reply to Text Fields Covered By Keyboard. iPadOS App
@Claude31 Thanks allot, it's a hard task to leave it on developer to solve it ! Its in SwiftUI. Kind Regards
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’25
Reply to Text Fields Covered By Keyboard. iPadOS App
@Claude31 now another isue is when text field get focused and keyboard shows content of side bar jumps up, is that a known issue ! its very strange ! is it aa known bug or something ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’25
Reply to Multi Platform App
@szymczyk Thanks allot, that was very helpful. Kind Regards
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Jan ’25
Reply to Reserving App Name
Thanks allot, SKU means ?
Replies
Boosts
Views
Activity
Jan ’25
Reply to Disable Landscape For iPhone
Thanks allot
Replies
Boosts
Views
Activity
Jan ’25
Reply to App Pricing
Thanks Allot
Replies
Boosts
Views
Activity
Jan ’25
Reply to Reserving App Name
Oh I see, thanks allot, and this can be done in the Connect App or just tgrough web page ? — Kind Regards
Replies
Boosts
Views
Activity
Jan ’25