I have a view showing messages in a team that are filtered using @Fetchrequest with a fixed predicate \'Developers\'.
struct ChatView: View {
@FetchRequest(
Modified @FKDev answer to work, as it throws an error, I like this answer because of its cleanliness and consistency with the rest of SwiftUI. Just need to remove the parentheses from the fetch request. Although @Antoine Weber answer works just the same.
But I am experience an issue with both answers, include mine below. This causes a weird side effect where some rows not related to the fetch request animate off screen to the right then back on screen from the left only the first time the fetch request data changes. This does not happen when the fetch request is implemented the default SwiftUI way.
UPDATE: Fixed the issue of random rows animating off screen by simply removing the fetch request animation argument. Although if you need that argument, i'm not sure of a solution. Its very odd as you would expect that animation argument to only affect data related to that fetch request.
@Binding var teamName: String
@FetchRequest var messages: FetchedResults
init() {
var predicate: NSPredicate?
// Can do some control flow to change the predicate here
predicate = NSPredicate(format: "team.name == %@", teamName)
self._messages = FetchRequest(
entity: Message.entity(),
sortDescriptors: [],
predicate: predicate,
// animation: .default)
}