Swift 中 Int 类型比较错误:'===' 运算符的用法
The error is occurring because the '===' operator is used for reference equality comparison in Swift, and it can only be used with reference types (i.e., classes or class-constrained types).
In this case, you are trying to use it with integers, which are value types. Instead, you should use the '==' operator to compare the values of the integers.
Here's the corrected code:
public class Solution {
func equal(_ a: Int, _ b: Int) -> [Bool] {
return [a == b, a == b]
}
}
This code will compare the values of a and b using the '==' operator, and return an array with two elements: the result of the comparison (true if the values are equal, false otherwise) repeated twice.
原文地址: https://www.cveoy.top/t/topic/p8SL 著作权归作者所有。请勿转载和采集!