[英]Objective-C, why do these NSArrays not match?
我有兩個要比較的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
)
-[NSBundle executableArchitectures]
返回一個NSNumber
對象數組,而不是NSString
對象,因此您要傳遞的數組中沒有字符串。 如果你改變
NSArray *one = [NSArray arrayWithObjects:@"16777223",@"7", nil];
至
NSArray *one = [NSArray arrayWithObjects:[NSNumber numberWithUnsignedInteger:NSBundleExecutableArchitectureX86_64],
[NSNumber numberWithUnsignedInteger:NSBundleExecutableArchitectureI386],
nil];
您的代碼應該可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.