我有两个我正在比较的NSArrays - 在NSLog输出中它们看起来完全一样,但它们在某种程度上并不相同。如果我将NSArray转换为NSString,我会得到相同的结果。将它们与自己进行比较将是平等的。我怎样才能确定为什么一和二不相等?谢谢。
- (void)confused:(NSArray *)two {
NSArray *one = [NSArray arrayWithObjects:@"16777223", @"7", nil];
NSArray *two = [[NSBundle bundleWithPath:@"/path/to/bundle"] executableArchitectures];
// NSArray "two" shows as 16277223, 7 in NSLog
if ([two firstObjectCommonWithArray:(NSArray *)one])
{
NSLog(@"- it's equal %@ %@", one, two);
// if array one matches array two then this will output
}
else {
NSLog(@"- it's NOT equal %@ %@", one, two);
}
return;
}
这是控制台的输出:
myApp (
16777223,
7
)
myApp (
16777223,
7
)
myApp - it's NOT equal (
16777223,
7
)(
16777223,
7
)
答案 0 :(得分:1)
-[NSBundle executableArchitectures]
返回NSNumber
个对象的数组,而不是NSString
个对象,因此您传入的数组中没有字符串。如果你改变了
NSArray *one = [NSArray arrayWithObjects:@"16777223",@"7", nil];
到
NSArray *one = [NSArray arrayWithObjects:[NSNumber numberWithUnsignedInteger:NSBundleExecutableArchitectureX86_64],
[NSNumber numberWithUnsignedInteger:NSBundleExecutableArchitectureI386],
nil];
您的代码应该有效。