Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

saleh.hi.62

macrumors member
Original poster
Jul 25, 2011
95
0
Hello guys,

here i am trying to compare the hosts of 2 URLs, eventhought 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!");
	}
 
Hello guys,

here i am trying to compare the hosts of 2 URLs, eventhought 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!");
	}

What exactly does the "==" operator compare?

Your code will only match the hosts if by coincidence both are exactly the same object. Not objects that are equal, but the same. You have to actually compare them. Then you need to read up on when url hosts should be considered equal. For example, is Facebook.com the same as facebook.com?
 
You're effectively using MR to crowd source whatever download agent you're building.

Look at the documentation for NSString, there are a lot of different methods to do what you are looking for.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.