笔记记录
NSArray *array1 = @[@"1",@"2",@"3"];
NSArray *array2 = @[@"1",@"2",@"3"];
NSArray *array3 = array1;
NSMutableArray *array4 = @[@"1",@"2",@"3"].mutableCopy;
NSMutableArray *array5 = @[@"1",@"2",@"3"].mutableCopy;
NSMutableArray *array6 = array4;
NSArray *array7 = array1;
NSArray *array8 = @[@"1",@"2"];
NSMutableArray *array9 = @[@"1",@"2"].mutableCopy;
NSLog(@"%@",@([array1 isEqual:array2]));
NSLog(@"%@",@([array1 isEqual:array3]));
NSLog(@"%@",@([array4 isEqual:array5]));
NSLog(@"%@",@([array6 isEqual:array3]));
NSLog(@"%@",@([array7 isEqual:array6]));
NSLog(@"%@",@([array8 isEqual:array1]));
NSLog(@"%@",@([array9 isEqual:array4]));
打印结果
1
1
1
1
1
0
0
由此可见 NSArray 和 NSMutableArray 的 equal: 方法 是比较的 数组里面 每个元素是否相等,跟地址 ,可变数组,不可变数组 没关系
数组 equal: 方法伪代码
- (BOOL)isEqualArray:(NSArray *)array {
for (id selfObject in self) {
for (id otherObject in array) {
if ([selfObject isEqual:otherObject] == NO) {
return NO;
}
}
}
return YES;
}
网友评论