I am trying to fetch objects whose date property is within today. When I give a predicate to @Query macro to filter data like this:
@Query(filter: #Predicate<Note> { Calendar.current.isDateInToday($0.date) })
private var notes: [Note]
I get this error
My Note model:
@Model
final class Note {
var date: Date
var title: String
init(date: Date = Date.now, title: String) {
self.date = date
self.title = title
}
}
My View:
struct ContentView: View {
@Environment(\.modelContext) private var modelContext
@Query(filter: #Predicate<Note> { Calendar.current.isDateInToday($0.date) })
private var notes: [Note]
@State private var newNoteTitle = ""
var body: some View {
NavigationStack {
List {
ForEach(notes) { note in
Text(note.title)
}
HStack {
TextField("New Note", text: $newNoteTitle)
Button {
modelContext.insert(Note(title: newNoteTitle))
newNoteTitle = ""
} label: {
Image(systemName: "plus.circle.fill")
}
.disabled(newNoteTitle.isEmpty)
}
}
.navigationTitle("Today")
}
}
}
Post
Replies
Boosts
Views
Activity
I created a package using "File > New > Package" and now I want to add a new Asset Catalog to this package. With my package selected in the project navigator I select "File > New > File" but it creates a Swift file instead of showing the Template Selection dialog
Ref: https://developer.apple.com/documentation/xcode/managing-assets-with-asset-catalogs#Create-a-new-asset-catalog