URL host comparison

Discussion in 'Mac Programming' started by saleh.hi.62, Nov 22, 2011.

  1. saleh.hi.62 macrumors member

    Jul 25, 2011
    Hello guys,

    here i am trying to compare the hosts of 2 URLs, eventhought that hosts are the same it does not respond why? !

    	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!");
  2. gnasher729 macrumors P6


    Nov 25, 2005
    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?
  3. jared_kipe macrumors 68030


    Dec 8, 2003
    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.

Share This Page