Predicate to filter against array of items

Since Predicate is both Codable and Sendable, it requires that everything the predicate captures (i.e. all instances captured by the closure) are also Codable and Sendable. In your case, your predicate is capturing tags which has the type [Tag], and it looks like from the declaration of Tag that it is neither Codable nor Sendable, which is likely what the compiler is trying to tell you here.

To resolve this, can you capture the list of UUIDs instead (since UUID is Codable & Sendable)? For example:

let tags: [Tag] = ...
let uuids = tags.map(\.uuid)
#Predicate<Place> { place in
  place.tags.allSatisfy { tag in
    uuids.contains(tag.uuid)
  }
}
2 Likes