I have a function with a parameter of type [String]. I can call the function and it executes successfully. However, I recently encountered an error when adding a new data source, and I'm trying to debug. I'm switching on the array parameter, using the same values I'm passing in to call the function. Swift throws an error:
Swift Expression pattern of type [String] cannot match values of type [String]
Here's the section of code I'm working with:
func calcRelevance(array: [String]) {
/* block of code */
if relevanceArr.count >= 1 {
//do something
} else {
switch array {
case self.someArray:
self.label.text = "No results returned from some data source"
case self.someOtherArray:
self.label.text = "No results returned from some other data source"
default:
self.label.text = "Your search yielded no results. Please refine your search by tapping back and using more relevant search terms"
}
}
}
As I typed this out I realized that I may not be able to use a switch block inside an if statement. I'm not sure if control flow allows for such, which seems odd to get a type error from it if that's the case.
Also, I've looked at Switching on UIButton title: Expression pattern of type 'String' cannot match values of type 'String?!' and it has to do with unwrapping optionals which I don't believe applies here.