Getting the error: "No exact matches in reference to static method 'buildExpression'" in the following code:
var categoryNames: [String] = []
ForEach(categories, id: \.self) { category in
if let categoryName = category.cCategoryName {
categoryNames.append(categoryName)
}
}
Note that categories is a variable pointing to my coredata entity and cCategoryName is an attribute of that entity.
I don't have any methods in any of my code called "buildExpression".
Is this a bug?
Thanks!
Xcode 14.3 has some great improvements to the speed and accuracy of compiling SwiftUI code, but because these changes are still pretty new there are a few cases where the error message is misleading.
In this case, the error is not at the line where the error is reported. One trick I've discovered to look very carefully at the rest of the SwiftUI code, and see if you can see part of an expression that's not syntax-highlighted in the expected color. That's usually where the (or an) error is.
It's possible to see the error in your code directly, though. It's this line:
categoryNames.append(categoryName)
You're defining a list of things (ForEach
) in a SwiftUI description of a View
. This is not procedural code, so you can't just do things as you normally would. In particular, you can't call the append
function here.
How you resolve this depends on what you're actually doing around this code (the parts you left out). If you want to build a list of all the category names, you'll have to do it as a separate step, but it's hard to give a recommendation without additional context.