这里我试图比较2个网址的主机。即使主机是相同的,它也没有回应原因!
代码:
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!");
}
答案 0 :(得分:3)
您需要使用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]主机匹配