Posted By

gerhardsletten on 10/18/09


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

alladinian
avanadra
cnathan


Categories in Objective-C


 / Published in: Objective C
 

URL: http://www.cocoadevcentral.com/d/learn_objectivec/

  1. #import <Cocoa/Cocoa.h>
  2. @interface NSString (Utilities)
  3. - (BOOL) isURL;
  4. @end
  5.  
  6. #import "NSString-Utilities.h"
  7. @implementation NSString (Utilities)
  8.  
  9. - (BOOL) isURL {
  10. if ( [self hasPrefix:@"http://"] )
  11. return YES;
  12. else
  13. return NO;
  14. }
  15. @end
  16.  
  17. // To use this:
  18.  
  19. NSString* string1 = @"http://pixar.com/";
  20. NSString* string2 = @"Pixar";
  21.  
  22. if ( [string1 isURL] )
  23. NSLog (@"string1 is a URL");
  24.  
  25. if ( [string2 isURL] )
  26. NSLog (@"string2 is a URL");

Report this snippet  

You need to login to post a comment.