问题
Here I am trying to compare the hosts of 2 URLs. Even though that hosts are the same it does not respond why!
Code:
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!");
}
回答1:
You need to use 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!");
}
Result
2011-11-23 11:55:06.182 TestApp[14404:207] hosts are matched
来源:https://stackoverflow.com/questions/8239274/url-host-comparison