Ian_Ward
(Ian Ward)
July 2, 2020, 5:25pm
1
Hey All - we’ve released a blog post and demo app that details how to use RealmSwift’s Frozen Object implementation along with how to integrate with SwiftUI and Combine. Please have a look here:
https://www.mongodb.com/article/realm-cocoa-swiftui-combine
We are eager to have you try it out and welcome your feedback
Best
Ian
2 Likes
Sees to work a treat for getting a ‘live’ list of unique keywords from database records.
var subjects: Results<Asset> {
return assets.sorted(byKeyPath: "subject").distinct(by: ["subject"])
}
func filteredSubjectsCollection() -> AnyRealmCollection<Asset> {
return AnyRealmCollection(self.subjects)
}
// Subjects
DisclosureGroup(isExpanded: $model.isSubjectsShowing) {
VStack(alignment:.trailing, spacing: 4) {
ForEach(filteredSubjectsCollection().freeze()) { asset in
CheckBoxSelection(label: asset.subject, isSelected: self.model.selectedSubjects.contains(asset.subject))
.onTapGesture { self.model.addSubject(subject: asset.subject) }
}
}.frame(maxWidth:.infinity)
.padding(.leading, 20).padding(.trailing, 0)
} label: {
HStack(alignment:.center) {
Image(systemName: "flag")
CheckBoxSelection(label: "Subjects", isSelected: self.model.selectAllSubjects)
.font(.system(.title3))
.onTapGesture { self.addAllSubjects() }
}.padding([.top, .bottom], 8).foregroundColor(.secondary)
.padding(.trailing, 1)
}