这里我试图比较2个url的主机。即使主机是相同的,它也不回应为什么!
代码:NSURL *url=[NSURL URLWithString:@"http://www.facebook.com/"?ref=logo" ];
NSURL *domain=[ NSURL URLWithString:@"http://www.facebook.com" ];
if ( [url host]==[domain host] ) {
NSLog(@"hosts are matched");
}else {
NSLog(@"hosts are not matched!");
}
您需要使用isEqualToString:
NSURL *url=[NSURL URLWithString:@"http://www.facebook.com/?ref=logo" ];
NSURL *domain=[ NSURL URLWithString:@"http://www.facebook.com" ];
if ( [[url host] isEqualToString: [domain host]] ) {
NSLog(@"hosts are matched");
}else {
NSLog(@"hosts are not matched!");
}
结果2011-11-23 11:55:06.182 TestApp[14404:207]主机匹配