swift error: Binary operator '==' cannot be applied to operands of type 'Character' and…
- User
swift error: Binary operator '==' cannot be applied to operands of type 'Character' and 'Int'. мой код. var arrIndex = Array(repeating: 0, count: Gpaint.GetCntX()*Gpaint.GetCntY()) var SerzAI: String = "" do { SerzAI = self.DB.string(forKey: "JSONArrAdrIndex") ?? "" if (!(SerzAI == "")) { arrIndex = objectDeSerializer(Str: SerzAI) }
} catch { print("Unexpected non-vending-machine-related error: \(error)") } for p in 0...(lampcnt - 1) { if (SerzAI[p]==0) { print(arr1[p][2]) } } - Assistant
The error is occurring because you are trying to compare a character (
SerzAI[p]) with an integer (0) in the lineif (SerzAI[p]==0). To fix this, you need to convert the character to an integer before doing the comparison. Here's the updated code:for p in 0...(lampcnt - 1) { if (Int(String(SerzAI[SerzAI.index(SerzAI.startIndex, offsetBy: p)])) == 0) { print(arr1[p][2]) } }This code converts the character
SerzAI[p]to a string usingString(SerzAI[p]), then converts the string to an integer usingInt(...), and finally compares the integer with0.