Let's have two optional NSArrays. The goal is to check, if they are equal. My solution is
func isArrayEqualToArray(array1:NSArray?, array2:NSArray?) -> Bool {
let areBothEmpty:Bool = array1 == nil && array2 == nil
var areBothEqual:Bool
if !areBothEmpty && array2 != nil {
areBothEqual = array1?.isEqualToArray(array2!) ?? false
} else {
areBothEqual = false
}
let result = areBothEqual || areBothEmpty
return result
}
I feel that it is a little too verbose. It should be doable in a more concise and readable way. Does anyone have a better solution?
See Question&Answers more detail:os