I have an array of objects called array and its type is votes. In the objects of the array there is a field called nameSubject that is a String.
How can I pass my array and the String that I want to compare with the name of the subject? This is my function:
static func binarySearch(inputArr: [votes], searchItem: String)->Int?{
var lowerIndex = 0;
var upperIndex = inputArr.count - 1
while (true) {
var currentIndex = (lowerIndex + upperIndex)/2
if(inputArr[currentIndex] == searchItem) {
return currentIndex
} else if (lowerIndex > upperIndex) {
return nil
} else {
if (inputArr[currentIndex] > searchItem) {
upperIndex = currentIndex - 1
} else {
lowerIndex = currentIndex + 1
}
}
}
}
The error is in the first and in the second if and says this: Binary operator '==' cannot be applied to operands of type 'votes' and 'String'"
nameSubjecttovotesobjectsVote