It is quite simple:
func isArrayEqualToArray(array1: NSArray?, array2: NSArray?) -> Bool {
return array1 == array2
}
does exactly what you want.
Why does it work? Here ==
is the operator that compares optionals
func ==<T : Equatable>(lhs: T?, rhs: T?) -> Bool
and that gives true
if both operands are nil
, or of both
operands are non-nil and the unwrapped operands are equal.
Also NSArray
inherits from NSObject
which conforms to Equatable
,
and comparing NSObject
s with ==
uses the isEqual:
method, which is
implemented as isEqualToArray:
on NSArray
.
Therefore
array1 == array2
gives the same result as
array1.isEqualToArray(array2)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…