Categories in Objective-C


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  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");

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.