So I've found a way to convert fetched results to an array of the same data type, and not only that but filter them with the fetch request given a string:
func searchResults(searchingFor: String)->[Recipe]{
var filteredRecipeList=[Recipe]()
@FetchRequest(sortDescriptors: [SortDescriptor(\.date, order: .reverse)], predicate: NSPredicate(format: "title CONTAINS[c] %@",searchingFor)) var filteredResults: FetchedResults<Recipe>
for recipe in filteredResults {
filteredRecipeList.append(recipe)
}
return filteredRecipeList
}
To clarify, this would ideally return an array with a list of Recipes that contain the given string in the title. In theory this should work just fine, but I'm getting a weird error. I've never seen an error like this and I'm not sure how to understand it. It is purple with a yellow warning. The error says "Accessing StateObject's object without being installed on a View. This will create a new instance each time." How do I get around this issue to accomplish what I'm trying to accomplish.
Thanks in advance for any help whatsoever. I'll upvote anyone with any bit of helpful information. Have a good one!